Chandranshu Jain commited on
Commit
4c038d7
1 Parent(s): 2352722

Upload 4 files

Browse files
Files changed (4) hide show
  1. .env +1 -0
  2. app.py +34 -0
  3. app2.py +54 -0
  4. requirements.txt +5 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ OPEN_API_KEY="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"
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Q&A Chatbot
2
+ from langchain_openai import OpenAI
3
+
4
+ from dotenv import load_dotenv
5
+
6
+ load_dotenv() # take environment variables from .env.
7
+
8
+ import streamlit as st
9
+ import os
10
+
11
+
12
+ ## Function to load OpenAI model and get respones
13
+
14
+ def get_openai_response(question):
15
+ llm=OpenAI(openai_api_key=os.environ["OPEN_API_KEY"],temperature=0.5)
16
+ response=llm.invoke(question)
17
+ return response
18
+
19
+ ##initialize our streamlit app
20
+
21
+ st.set_page_config(page_title="Q&A Chatbot")
22
+
23
+ st.header("Q&A Chatbot")
24
+
25
+ input=st.text_input("Question: ",key="input")
26
+ response=get_openai_response(input)
27
+
28
+ submit=st.button("Answer")
29
+
30
+ ## If ask button is clicked
31
+
32
+ if submit:
33
+ st.subheader("The Answer is")
34
+ st.write(response)
app2.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Q&A Chatbot
2
+ from langchain_openai import OpenAI
3
+
4
+ from dotenv import load_dotenv
5
+
6
+ load_dotenv() # take environment variables from .env.
7
+
8
+ import streamlit as st
9
+ import os
10
+
11
+ from langchain.prompts import PromptTemplate
12
+ from langchain.chains import LLMChain
13
+ from langchain.chains import SequentialChain
14
+
15
+
16
+ ## Function to load OpenAI model and get respones
17
+
18
+ def get_openai_response(country_name):
19
+ llm=OpenAI(openai_api_key=os.environ["OPEN_API_KEY"],temperature=0.5)
20
+ capital_template=PromptTemplate(input_variables=['country'],
21
+ template="Please tell me the capital of the {country}")
22
+ capital_chain=LLMChain(llm=llm,prompt=capital_template,output_key="capital")
23
+
24
+ famous_template=PromptTemplate(input_variables=['capital'],
25
+ template="Suggest me some amazing places to visit in {capital}")
26
+ famous_chain=LLMChain(llm=llm,prompt=famous_template,output_key="places")
27
+
28
+ eats_template=PromptTemplate(input_variables=['capital'],
29
+ template="Suggest the top 5 famous dishes to eat in {capital}")
30
+ eats_chain=LLMChain(llm=llm,prompt=eats_template,output_key="dishes")
31
+
32
+ chain=SequentialChain(chains=[capital_chain,famous_chain,eats_chain],
33
+ input_variables=['country'],
34
+ output_variables=['capital',"places","dishes"])
35
+
36
+ response=chain.invoke({'country':country_name})
37
+ return response
38
+
39
+ ##initialize our streamlit app
40
+
41
+ st.set_page_config(page_title="Q&A Chatbot")
42
+
43
+ st.header("January Capital Guide")
44
+
45
+ input=st.text_input("Enter Country Name: ",key="input")
46
+ response=get_openai_response(input)
47
+
48
+ submit=st.button("Answer")
49
+
50
+ ## If ask button is clicked
51
+
52
+ if submit:
53
+ st.subheader("The Answer is")
54
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ streamlit
4
+ huggingface_hub
5
+ python-dotenv