Upload app.py
Browse files
app.py
CHANGED
@@ -19,42 +19,42 @@ if 'conversation' not in st.session_state:
|
|
19 |
st.session_state['conversation'] =None
|
20 |
if 'messages' not in st.session_state:
|
21 |
st.session_state['messages'] =[]
|
22 |
-
if 'API_Key' not in st.session_state:
|
23 |
-
st.session_state['API_Key'] =''
|
24 |
|
25 |
# Setting up the page title and header
|
26 |
st.set_page_config(page_title="Chat GPT Clone", page_icon=":robot_face:")
|
27 |
st.markdown("<h1 style='text-align: center;'>How can I assist you? </h1>", unsafe_allow_html=True)
|
28 |
st.sidebar.title("😎")
|
29 |
-
st.session_state['API_Key']= st.sidebar.text_input("What's your API key?",type="password")
|
30 |
summarise_button = st.sidebar.button("Summarise the conversation", key="summarise")
|
31 |
if summarise_button:
|
32 |
summarise_placeholder = st.sidebar.write("Nice chatting with you my friend ❤️:\n\n"+st.session_state['conversation'].memory.buffer)
|
33 |
|
34 |
# Function to get response from the model
|
35 |
-
def getresponse(userInput
|
36 |
"""
|
37 |
This function takes user input and api key as arguments, and returns the model's response.
|
38 |
"""
|
39 |
if st.session_state['conversation'] is None:
|
40 |
llm = OpenAI(
|
41 |
temperature=0,
|
42 |
-
openai_api_key
|
|
|
43 |
model_name='gpt-3.5-turbo-instruct'
|
44 |
)
|
|
|
|
|
45 |
st.session_state['conversation'] = ConversationChain(
|
46 |
llm=llm,
|
47 |
verbose=True,
|
48 |
memory=ConversationSummaryMemory(llm=llm)
|
49 |
)
|
|
|
50 |
response=st.session_state['conversation'].predict(input=userInput)
|
51 |
print(st.session_state['conversation'].memory.buffer)
|
52 |
return response
|
53 |
|
54 |
-
# Setting up containers for user input and model response
|
55 |
-
response_container = st.container()
|
56 |
-
container = st.container()
|
57 |
-
|
58 |
# Function to clear the conversation
|
59 |
def clear():
|
60 |
"""
|
@@ -64,6 +64,15 @@ def clear():
|
|
64 |
st.session_state['conversation'].memory.clear()
|
65 |
st.session_state['messages'] =[]
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
# Setting up the user input form
|
68 |
with container:
|
69 |
with st.form(key='my_form', clear_on_submit=True):
|
@@ -77,7 +86,7 @@ with container:
|
|
77 |
# Handling form submission
|
78 |
if submit_button:
|
79 |
st.session_state['messages'].append(user_input)
|
80 |
-
model_response=getresponse(user_input
|
81 |
st.session_state['messages'].append(model_response)
|
82 |
|
83 |
# Displaying the conversation
|
|
|
19 |
st.session_state['conversation'] =None
|
20 |
if 'messages' not in st.session_state:
|
21 |
st.session_state['messages'] =[]
|
22 |
+
#if 'API_Key' not in st.session_state:
|
23 |
+
#st.session_state['API_Key'] =''
|
24 |
|
25 |
# Setting up the page title and header
|
26 |
st.set_page_config(page_title="Chat GPT Clone", page_icon=":robot_face:")
|
27 |
st.markdown("<h1 style='text-align: center;'>How can I assist you? </h1>", unsafe_allow_html=True)
|
28 |
st.sidebar.title("😎")
|
29 |
+
#st.session_state['API_Key']= st.sidebar.text_input("What's your API key?",type="password")
|
30 |
summarise_button = st.sidebar.button("Summarise the conversation", key="summarise")
|
31 |
if summarise_button:
|
32 |
summarise_placeholder = st.sidebar.write("Nice chatting with you my friend ❤️:\n\n"+st.session_state['conversation'].memory.buffer)
|
33 |
|
34 |
# Function to get response from the model
|
35 |
+
def getresponse(userInput):
|
36 |
"""
|
37 |
This function takes user input and api key as arguments, and returns the model's response.
|
38 |
"""
|
39 |
if st.session_state['conversation'] is None:
|
40 |
llm = OpenAI(
|
41 |
temperature=0,
|
42 |
+
#openai_api_key from spaces secret
|
43 |
+
#openai_api_key=api_key,
|
44 |
model_name='gpt-3.5-turbo-instruct'
|
45 |
)
|
46 |
+
#Creating a new conversation chain
|
47 |
+
#ConversationChain is a class that handles the conversation between the user and the model
|
48 |
st.session_state['conversation'] = ConversationChain(
|
49 |
llm=llm,
|
50 |
verbose=True,
|
51 |
memory=ConversationSummaryMemory(llm=llm)
|
52 |
)
|
53 |
+
#
|
54 |
response=st.session_state['conversation'].predict(input=userInput)
|
55 |
print(st.session_state['conversation'].memory.buffer)
|
56 |
return response
|
57 |
|
|
|
|
|
|
|
|
|
58 |
# Function to clear the conversation
|
59 |
def clear():
|
60 |
"""
|
|
|
64 |
st.session_state['conversation'].memory.clear()
|
65 |
st.session_state['messages'] =[]
|
66 |
|
67 |
+
|
68 |
+
# -- GUI --
|
69 |
+
|
70 |
+
# Setting up containers for user input and model response
|
71 |
+
response_container = st.container()
|
72 |
+
container = st.container()
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
# Setting up the user input form
|
77 |
with container:
|
78 |
with st.form(key='my_form', clear_on_submit=True):
|
|
|
86 |
# Handling form submission
|
87 |
if submit_button:
|
88 |
st.session_state['messages'].append(user_input)
|
89 |
+
model_response=getresponse(user_input)
|
90 |
st.session_state['messages'].append(model_response)
|
91 |
|
92 |
# Displaying the conversation
|