eaglelandsonce commited on
Commit
0a3b0a1
·
1 Parent(s): e66e35b

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +40 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.llms import OpenAI
3
+ from langchain.agents import load_tools, initialize_agent, AgentType
4
+ import os
5
+
6
+ # Set up Streamlit interface
7
+ st.title('Weather Q&A using Langchain')
8
+ # Adding the markdown message
9
+ st.markdown("""
10
+ I'm genuinely impressed. Leveraging prompt engineering, I was able to craft this program in just 5 minutes, and it's fully functional! All I did was instruct ChatGPT to integrate langchain and streamlit, set up inputs for the API keys, pose a weather-related question, and use the details from the [LangChain OpenWeatherMap link](https://python.langchain.com/docs/integrations/tools/openweathermap) as a coding and output guide. Now, envisioning a solution is all it takes. It's auto-magical! I may have been a terrible programmer, but I\'m an amazing prompt engineer, bless the Lord!
11
+ """)
12
+
13
+ st.sidebar.header('API Configuration')
14
+
15
+ # Input for OpenAI API key and OpenWeather API key in the Streamlit sidebar
16
+ os.environ["OPENAI_API_KEY"] = st.sidebar.text_input('OpenAI API Key:', value='', type='password')
17
+ os.environ["OPENWEATHERMAP_API_KEY"] = st.sidebar.text_input('OpenWeather API Key:', value='', type='password')
18
+
19
+ # Input for question about the weather
20
+ question = st.text_input('Ask a question about the weather (e.g., "What\'s the weather like in London?"):')
21
+
22
+ # Initialize Langchain's OpenAI and agent_chain only once API keys are provided
23
+ if os.environ["OPENAI_API_KEY"] and os.environ["OPENWEATHERMAP_API_KEY"]:
24
+ try:
25
+ llm = OpenAI(temperature=0)
26
+ tools = load_tools(["openweathermap-api"], llm)
27
+ agent_chain = initialize_agent(
28
+ tools=tools, llm=llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
29
+ )
30
+
31
+ # If a question is provided, proceed to get an answer
32
+ if question:
33
+ response = agent_chain.run(question)
34
+ st.write(response)
35
+ except Exception as e:
36
+ st.warning("There was an error processing your request.")
37
+ st.write(f"Details: {e}")
38
+ st.write("Please provide more specific information. For example, you may need to provide the country sucn as Florence Kentucky US.")
39
+ else:
40
+ st.warning("Please provide your API keys in the left sidebar!")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ openai
3
+ langchain
4
+ pyowm