Chandranshu Jain commited on
Commit
68b71c3
1 Parent(s): b533b81

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.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)