Shankarm08 commited on
Commit
17151a7
·
verified ·
1 Parent(s): 326093d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -2,35 +2,33 @@
2
  #Once you have Streamlit installed, you can import it into your Python script using the import statement,
3
 
4
  import streamlit as st
5
-
6
-
7
  from langchain.chat_models import ChatOpenAI
 
8
 
9
- #Function to return the response
10
  def load_answer(question):
11
- llm =ChatOpenAI(model_name="gpt-4-turbo-preview",temperature=0)
12
- answer=llm(question)
13
- return answer
 
 
14
 
15
-
16
- #App UI starts here
17
  st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
18
  st.header("LangChain Demo")
19
 
20
- #Gets the user input
21
  def get_text():
22
  input_text = st.text_input("You: ", key="input")
23
  return input_text
24
 
 
 
25
 
26
- user_input=get_text()
27
- response = load_answer(user_input)
28
-
29
- submit = st.button('Generate')
30
-
31
- #If generate button is clicked
32
- if submit:
33
-
34
  st.subheader("Answer:")
35
-
36
- st.write(response)
 
 
 
2
  #Once you have Streamlit installed, you can import it into your Python script using the import statement,
3
 
4
  import streamlit as st
 
 
5
  from langchain.chat_models import ChatOpenAI
6
+ from langchain.schema import HumanMessage # Used to pass a message from the user
7
 
8
+ # Function to return the response
9
  def load_answer(question):
10
+ llm = ChatOpenAI(model_name="gpt-4", temperature=0)
11
+
12
+ # The input to the model must be a list of messages, specifically a HumanMessage.
13
+ answer = llm([HumanMessage(content=question)])
14
+ return answer.content # Extract the content of the response
15
 
16
+ # App UI starts here
 
17
  st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
18
  st.header("LangChain Demo")
19
 
20
+ # Gets the user input
21
  def get_text():
22
  input_text = st.text_input("You: ", key="input")
23
  return input_text
24
 
25
+ user_input = get_text()
26
+ submit = st.button('Generate')
27
 
28
+ # If generate button is clicked
29
+ if submit and user_input:
 
 
 
 
 
 
30
  st.subheader("Answer:")
31
+ response = load_answer(user_input) # Generate the response
32
+ st.write(response)
33
+ elif submit and not user_input:
34
+ st.warning("Please enter a question.")