raghavgpt001 commited on
Commit
c6efc44
1 Parent(s): bcaf794

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +73 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_chat import message
3
+ from langchain_openai import OpenAI
4
+ from langchain.chains import ConversationChain
5
+ from langchain.chains.conversation.memory import (ConversationSummaryMemory)
6
+ import os
7
+
8
+ os.environ["OPENAI_API_KEY"] = "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"
9
+
10
+ if 'conversation' not in st.session_state:
11
+ st.session_state['conversation'] =None
12
+ if 'messages' not in st.session_state:
13
+ st.session_state['messages'] =[]
14
+
15
+ # Setting page title and header
16
+ st.set_page_config(page_title="Chat GPT Clone", page_icon=":robot_face:")
17
+ st.markdown("<h1 style='text-align: center;'>How can I assist you? </h1>", unsafe_allow_html=True)
18
+
19
+
20
+ st.sidebar.title("😎")
21
+ summarise_button = st.sidebar.button("Summarise the conversation", key="summarise")
22
+ if summarise_button:
23
+ summarise_placeholder = st.sidebar.write("Nice chatting with you my friend ❤️:\n\n"+st.session_state['conversation'].memory.buffer)
24
+
25
+
26
+ def getresponse(userInput):
27
+
28
+ if st.session_state['conversation'] is None:
29
+ llm = OpenAI(
30
+ temperature=0,
31
+ model_name='gpt-3.5-turbo-instruct' #we can also use 'gpt-3.5-turbo'
32
+ )
33
+
34
+ st.session_state['conversation'] = ConversationChain(
35
+ llm=llm,
36
+ verbose=True,
37
+ memory=ConversationSummaryMemory(llm=llm)
38
+ )
39
+
40
+ response=st.session_state['conversation'].predict(input=userInput)
41
+ print(st.session_state['conversation'].memory.buffer)
42
+
43
+
44
+ return response
45
+
46
+
47
+
48
+ response_container = st.container()
49
+ # Here we will have a container for user input text box
50
+ container = st.container()
51
+
52
+
53
+ with container:
54
+ with st.form(key='my_form', clear_on_submit=True):
55
+ user_input = st.text_area("Your question goes here:", key='input', height=100)
56
+ submit_button = st.form_submit_button(label='Send')
57
+
58
+ if submit_button:
59
+ st.session_state['messages'].append(user_input)
60
+ model_response=getresponse(user_input)
61
+ st.session_state['messages'].append(model_response)
62
+
63
+
64
+ with response_container:
65
+ for i in range(len(st.session_state['messages'])):
66
+ if (i % 2) == 0:
67
+ message(st.session_state['messages'][i], is_user=True, key=str(i) + '_user')
68
+ else:
69
+ message(st.session_state['messages'][i], key=str(i) + '_AI')
70
+
71
+
72
+
73
+
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ langchain
2
+ langchain_openai
3
+ langchain_core
4
+ streamlit
5
+ openai
6
+ streamlit_chat