Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Conversational Q&A Chatbot
|
2 |
+
|
3 |
+
#imports
|
4 |
+
import streamlit as st
|
5 |
+
from langchain.schema import HumanMessage,SystemMessage,AIMessage
|
6 |
+
from langchain.chat_models import ChatOpenAI
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
import os
|
9 |
+
|
10 |
+
# Streamlit UI
|
11 |
+
st.set_page_config(page_title="Conversational Q&A Chatbot")
|
12 |
+
st.header("Hi there, let's chat!")
|
13 |
+
load_dotenv()
|
14 |
+
chat = ChatOpenAI(temperature=0.5)
|
15 |
+
|
16 |
+
if 'flowmessages' not in st.session_state:
|
17 |
+
st.session_state['flowmessages']=[
|
18 |
+
SystemMessage(content="You are a comedic AI assistant")
|
19 |
+
]
|
20 |
+
|
21 |
+
# Load OpenAI model and get response
|
22 |
+
def get_chatmodel_response(question):
|
23 |
+
|
24 |
+
st.session_state['flowmessages'].append(HumanMessage(content=question))
|
25 |
+
answer = chat(st.session_state['flowmessages'])
|
26 |
+
st.session_state['flowmessages'].append(AIMessage(content=answer.content))
|
27 |
+
return answer.content
|
28 |
+
|
29 |
+
input = st.text_input("Input: ", key="input")
|
30 |
+
response = get_chatmodel_response(input)
|
31 |
+
|
32 |
+
submit=st.button("Generate")
|
33 |
+
|
34 |
+
if submit:
|
35 |
+
st.subheader("Response:")
|
36 |
+
st.write(response)
|