Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain.schema import HumanMessage, SystemMessage, AIMessage, ChatMessage
|
| 3 |
+
from langchain.chat_models import ChatOpenAI
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="Conversational Q&A ChatBot")
|
| 6 |
+
st.header("Hey, Let's Chat")
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
chat = ChatOpenAI(temperature=0.5)
|
| 11 |
+
|
| 12 |
+
if 'flowmessages' not in st.session_state:
|
| 13 |
+
st.session_state['flowmessages'] = [
|
| 14 |
+
SystemMessage(content="You are a comedian AI assistant")
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
def get_chatmodel_response(question):
|
| 18 |
+
st.session_state['flowmessages'].append(HumanMessage(content=question))
|
| 19 |
+
answer = chat(st.session_state['flowmessages'])
|
| 20 |
+
st.session_state['flowmessages'].append(AIMessage(content=answer.content))
|
| 21 |
+
return answer.content
|
| 22 |
+
|
| 23 |
+
input_text = st.text_input("Input: ", key="input")
|
| 24 |
+
|
| 25 |
+
submit = st.button("Ask the question")
|
| 26 |
+
|
| 27 |
+
if submit:
|
| 28 |
+
st.subheader("The Response is")
|
| 29 |
+
response = get_chatmodel_response(input_text)
|
| 30 |
+
st.write(response)
|