Upload app1.py
Browse files
app1.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Conversational Q&A Chatbot
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
from langchain.schema import HumanMessage,SystemMessage,AIMessage
|
| 5 |
+
from langchain.chat_models import ChatOpenAI
|
| 6 |
+
|
| 7 |
+
## Streamlit UI
|
| 8 |
+
st.set_page_config(page_title="Conversational Q&A Chatbot")
|
| 9 |
+
st.header("Hey, Let's Chat with Langchain app by SOUMYAJIT GHOSH ")
|
| 10 |
+
|
| 11 |
+
from dotenv import load_dotenv
|
| 12 |
+
load_dotenv()
|
| 13 |
+
import os
|
| 14 |
+
|
| 15 |
+
chat=ChatOpenAI(temperature=0.5)
|
| 16 |
+
|
| 17 |
+
if 'flowmessages' not in st.session_state:
|
| 18 |
+
st.session_state['flowmessages']=[
|
| 19 |
+
SystemMessage(content="Yor are a comedian AI assitant")
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
## Function to load OpenAI model and get respones
|
| 23 |
+
|
| 24 |
+
def get_chatmodel_response(question):
|
| 25 |
+
|
| 26 |
+
st.session_state['flowmessages'].append(HumanMessage(content=question))
|
| 27 |
+
answer=chat(st.session_state['flowmessages'])
|
| 28 |
+
st.session_state['flowmessages'].append(AIMessage(content=answer.content))
|
| 29 |
+
return answer.content
|
| 30 |
+
|
| 31 |
+
input=st.text_input("Input: ",key="input")
|
| 32 |
+
response=get_chatmodel_response(input)
|
| 33 |
+
|
| 34 |
+
submit=st.button("Ask the question")
|
| 35 |
+
|
| 36 |
+
## If ask button is clicked
|
| 37 |
+
|
| 38 |
+
if submit:
|
| 39 |
+
st.subheader("The Response is")
|
| 40 |
+
st.write(response)
|