Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import streamlit as st
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
# import openai from langchain_openai
|
| 5 |
+
from langchain_openai import OpenAI
|
| 6 |
+
|
| 7 |
+
# Function to return the response
|
| 8 |
+
def load_answer(question):
|
| 9 |
+
llm = OpenAI(model_name="gpt-3.5-turbo-instruct",temperature=0)
|
| 10 |
+
|
| 11 |
+
answer=llm.invoke(question)
|
| 12 |
+
return answer
|
| 13 |
+
|
| 14 |
+
# App UI starts here
|
| 15 |
+
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
| 16 |
+
st.header("LangChain Demo")
|
| 17 |
+
|
| 18 |
+
# Gets the user input
|
| 19 |
+
def get_text():
|
| 20 |
+
# Add key to text_input to avoid re-rendering
|
| 21 |
+
input_text = st.text_input("User: ", key="input")
|
| 22 |
+
return input_text
|
| 23 |
+
|
| 24 |
+
# Get user input
|
| 25 |
+
user_input=get_text()
|
| 26 |
+
|
| 27 |
+
# Get response
|
| 28 |
+
response = load_answer(user_input)
|
| 29 |
+
|
| 30 |
+
# Add button to generate response
|
| 31 |
+
submit = st.button('Generate')
|
| 32 |
+
|
| 33 |
+
# If generate button is clicked
|
| 34 |
+
if submit:
|
| 35 |
+
|
| 36 |
+
st.subheader("Answer:")
|
| 37 |
+
|
| 38 |
+
st.write(response)
|