Spaces:
Runtime error
Runtime error
Char-lie-98
commited on
Commit
•
40926b5
1
Parent(s):
9a9e5de
First Commit
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Conversational Q&A Chatbot
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
from langchain.schema import HumanMessage,SystemMessage,AIMessage
|
5 |
+
from
|
6 |
+
import ChatOpenAI
|
7 |
+
|
8 |
+
## Streamlit UI
|
9 |
+
st.set_page_config(page_title="Conversational Q&A Chatbot")
|
10 |
+
st.header("Hey, Let's Chat")
|
11 |
+
|
12 |
+
from dotenv import load_dotenv
|
13 |
+
load_dotenv()
|
14 |
+
import os
|
15 |
+
|
16 |
+
chat=ChatOpenAI(temperature=0.5)
|
17 |
+
|
18 |
+
if 'flowmessages' not in st.session_state:
|
19 |
+
st.session_state['flowmessages']=[
|
20 |
+
SystemMessage(content="Yor are a comedian AI assitant")
|
21 |
+
]
|
22 |
+
|
23 |
+
## Function to load OpenAI model and get respones
|
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 |
+
input=st.text_input("Input: ",key="input")
|
33 |
+
response=get_chatmodel_response(input)
|
34 |
+
|
35 |
+
submit=st.button("Ask the question")
|
36 |
+
|
37 |
+
## If ask button is clicked
|
38 |
+
|
39 |
+
if submit:
|
40 |
+
st.subheader("The Response is")
|
41 |
+
st.write(response)
|