sumanthkv commited on
Commit
c75c03b
1 Parent(s): 7c8598e

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +47 -0
  2. openaiapikey.py +1 -0
  3. part1.py +17 -0
  4. pyvenv.cfg +8 -0
  5. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.llms import OpenAI
2
+ import streamlit as st
3
+ import os
4
+ from openaiapikey import openai_key
5
+ from langchain import PromptTemplate
6
+ from langchain.chains import LLMChain
7
+ from langchain.chains import SequentialChain
8
+
9
+
10
+
11
+ os.environ['OPENAI_API_KEY'] = openai_key
12
+
13
+ st.title('Book Summary')
14
+
15
+ input_text = st.text_input("Search the book you want")
16
+ #Prompt Template
17
+ first_input_prompt = PromptTemplate(input_variables = ['name'],
18
+ template="Provide me a summary of the book {name}"
19
+ )
20
+ #Open AI LLMS
21
+ llm = OpenAI(temperature=0.8)
22
+
23
+ #LLM Chain
24
+ chain1 = LLMChain(llm=llm, prompt = first_input_prompt, verbose=True, output_key = 'summaryofbook')
25
+ #Prompt Template
26
+
27
+ second_input_prompt = PromptTemplate(input_variables = ['summaryofbook'],
28
+ template="when was the {summaryofbook} published"
29
+ )
30
+ #LLM Chain
31
+
32
+ chain2 = LLMChain(llm=llm, prompt = second_input_prompt, verbose=True, output_key = 'bookpublishdate')
33
+
34
+
35
+ #Prompt Template
36
+
37
+ third_input_prompt = PromptTemplate(input_variables = ['summaryofbook'],
38
+ template="Please tell me about the authors of the {summaryofbook}"
39
+ )
40
+ #LLM Chain
41
+
42
+ chain3 = LLMChain(llm=llm, prompt = third_input_prompt, verbose=True, output_key = 'authorsofthebook')
43
+
44
+ parent_chain = SequentialChain(chains = [chain1, chain2, chain3], input_variables = ['name'], output_variables = ['summaryofbook', 'bookpublishdate','authorsofthebook'], verbose = True)
45
+
46
+ if input_text:
47
+ st.write(parent_chain({'name':input_text}))
openaiapikey.py ADDED
@@ -0,0 +1 @@
 
 
1
+ openai_key = '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'
part1.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.llms import OpenAI
2
+ import streamlit as st
3
+ import os
4
+ from openaiapikey import openai_key
5
+
6
+ os.environ['OPENAI_API_KEY'] = openai_key
7
+
8
+ st.title('Lang Chain Demo with Open AI')
9
+
10
+ input_text = st.text_input("Search the topic you want")
11
+
12
+
13
+ #Open AI LLMS
14
+ llm = OpenAI(temperature=0.8)
15
+
16
+ if input_text:
17
+ st.write(llm(input_text))
pyvenv.cfg ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ home = C:\Users\mmoin\Python3
2
+ implementation = CPython
3
+ version_info = 3.10.7.final.0
4
+ virtualenv = 20.13.0
5
+ include-system-site-packages = false
6
+ base-prefix = C:\Users\mmoin\Python3
7
+ base-exec-prefix = C:\Users\mmoin\Python3
8
+ base-executable = C:\Users\mmoin\Python3\python.exe
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ langchain
2
+ openai
3
+ streamlit