Spaces:
Sleeping
Sleeping
Commit
·
c8624a0
1
Parent(s):
c1e825c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as staticmethod
|
2 |
+
|
3 |
+
from langchain.chat_models import ChatOpenAI
|
4 |
+
from langchain.schema import (AIMessage, HumanMessage, SystemMessage)
|
5 |
+
|
6 |
+
st.set_page_config(page_title='Chat Model', page_icon=":robot:")
|
7 |
+
st.header("Hey, I'm 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.") #Telling the model
|
12 |
+
]
|
13 |
+
|
14 |
+
def load_answer(question):
|
15 |
+
st.session_state.sessionMessages.append(HumanMessage(content=question))
|
16 |
+
assistant_answer = chat(st.session_state.sessionMessages)
|
17 |
+
st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
|
18 |
+
return assistant_answer.content
|
19 |
+
|
20 |
+
def get_text():
|
21 |
+
input_text = st.text_input("You: ", key=input)
|
22 |
+
return input_text
|
23 |
+
chat = ChatOpenAI(temperature=0)
|
24 |
+
|
25 |
+
user_input = get_text()
|
26 |
+
submit = st.button('Generate')
|
27 |
+
|
28 |
+
if submit:
|
29 |
+
response = load_answer(user_input)
|
30 |
+
st.subheader("Answer:")
|
31 |
+
st,write(response, key=1)
|