Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from langchain.schema import HumanMessage, SystemMessage, AIMessage
|
4 |
+
from langchain.chat_models import ChatOpenAI
|
5 |
+
|
6 |
+
## Stream UI
|
7 |
+
st.set_page_config(page_title="Conversational Chat Bot")
|
8 |
+
st.header("Hey Lets chat")
|
9 |
+
|
10 |
+
from dotenv import load_dotenv
|
11 |
+
|
12 |
+
load_dotenv()
|
13 |
+
|
14 |
+
import os
|
15 |
+
|
16 |
+
chat=ChatOpenAI(temperature=0.7)
|
17 |
+
|
18 |
+
if 'flowmessages' not in st.session_state:
|
19 |
+
st.session_state["flowmessages"]=[
|
20 |
+
SystemMessage(content="You are Spoken english class teacher")
|
21 |
+
]
|
22 |
+
|
23 |
+
#functions to load open ai models and get responses
|
24 |
+
|
25 |
+
def get_chatmodel_response(question):
|
26 |
+
|
27 |
+
st.session_state["flowmessages"].append(HumanMessage(content=question))
|
28 |
+
answer=chat(st.session_state["flowmessages"])
|
29 |
+
st.session_state["flowmessages"].append(AIMessage(content=answer.content))
|
30 |
+
return answer.content
|
31 |
+
|
32 |
+
|
33 |
+
input=st.text_input("Input: ",key="input")
|
34 |
+
response=get_chatmodel_response(input)
|
35 |
+
|
36 |
+
submit=st.button("Ask the question")
|
37 |
+
|
38 |
+
## If ask button is clicked
|
39 |
+
|
40 |
+
if submit:
|
41 |
+
st.subheader("The Response is")
|
42 |
+
st.write(response)
|