Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from langchain.chat_models import ChatOpenAI
|
4 |
+
from langchain.schema import AIMessage, HumanMessage, SystemMessage
|
5 |
+
|
6 |
+
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
7 |
+
st.header("Hey, I am your Chat GPT")
|
8 |
+
|
9 |
+
if "sessionMessages" not in st.session_state:
|
10 |
+
st.session_state.sessionMessages = [
|
11 |
+
SystemMessage(content="You are a helpful assistant.")
|
12 |
+
]
|
13 |
+
|
14 |
+
def load_answer(question):
|
15 |
+
st.session_state.sessionMessages.append(HumanMessage(content=question))
|
16 |
+
|
17 |
+
model_response = chat(st.session_state.sessionMessages)
|
18 |
+
st.session_state.sessionMessages.append(model_response)
|
19 |
+
|
20 |
+
return model_response.content
|
21 |
+
|
22 |
+
|
23 |
+
def get_text():
|
24 |
+
text_input = st.text_input("You: ", key = input)
|
25 |
+
return text_input
|
26 |
+
|
27 |
+
chat = ChatOpenAI(temperature = 0)
|
28 |
+
|
29 |
+
user_input = get_text()
|
30 |
+
|
31 |
+
submit = st.button("Generate")
|
32 |
+
|
33 |
+
if submit:
|
34 |
+
response = load_answer(user_input)
|
35 |
+
st.subheader("Answer")
|
36 |
+
st.write(response, key = 1)
|