Prathamesh1420 commited on
Commit
c3940ed
·
verified ·
1 Parent(s): 1182eaf

Upload 2 files

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