dincertolga commited on
Commit
d657f82
·
verified ·
1 Parent(s): 88bc121

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +41 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from langchain.schema import HumanMessage,SystemMessage,AIMessage
4
+ from langchain.chat_models import ChatOpenAI
5
+ from langchain.llms import OpenAI
6
+
7
+ ## Streamlit UI
8
+ st.set_page_config(page_title="Conversational Q&A Chatbot")
9
+ st.header("Hey, Let's Chat")
10
+
11
+ #from dotenv import load_dotenv
12
+ #load_dotenv()
13
+ import os
14
+
15
+ def get_openai_response(question):
16
+ llm = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"), temperature = 0.5)
17
+ response = llm(question)
18
+ return response
19
+
20
+
21
+ # Initialize session state for chat history if it doesn't exist
22
+ if 'chat_history' not in st.session_state:
23
+ st.session_state['chat_history'] = []
24
+
25
+ input=st.text_input("Input: ",key="input")
26
+ submit=st.button("Ask the question")
27
+
28
+ if submit and input:
29
+ response = get_openai_response(input)
30
+ # Add user query and response to session state chat history
31
+ st.session_state['chat_history'].append(("You", input))
32
+ st.subheader("The Response is")
33
+
34
+ #for chunk in response:
35
+ st.write(response)
36
+ st.session_state['chat_history'].append(("Bot", response))
37
+ st.subheader("The Chat History is")
38
+
39
+ for role, texts in st.session_state['chat_history']:
40
+ st.write(f"{role}: {texts}")
41
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ python-dotenv
4
+ streamlit