Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -42,23 +42,22 @@ if 'key' not in st.session_state:
|
|
42 |
|
43 |
if st.session_state['key'] == st.secrets["login_key"]:
|
44 |
user_input = get_text()
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
if st.session_state['generated']:
|
51 |
-
for
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
output = openai_create(prompt)
|
57 |
-
print(f'{user_input} -> {output}')
|
58 |
-
st.session_state.past.append(user_input)
|
59 |
-
st.session_state.generated.append(output)
|
60 |
-
|
61 |
-
if st.session_state['generated']:
|
62 |
-
for i in range(len(st.session_state['generated'])-1, -1, -1):
|
63 |
-
message(st.session_state["generated"][i], key=str(i))
|
64 |
-
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
|
|
42 |
|
43 |
if st.session_state['key'] == st.secrets["login_key"]:
|
44 |
user_input = get_text()
|
45 |
+
if user_input:
|
46 |
+
prompt = 'The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.'
|
47 |
+
if st.session_state['generated']:
|
48 |
+
for past, generated in zip(st.session_state['past'], st.session_state['generated']):
|
49 |
+
if len(generated)>0:
|
50 |
+
prompt += f'\nHuman:{past}\nAI:{generated}'
|
51 |
+
prompt += f'\nHuman:{user_input}\nAI:'
|
52 |
+
print(prompt)
|
53 |
+
output = openai_create(prompt)
|
54 |
+
print(f'{user_input} -> {output}')
|
55 |
+
st.session_state.past.append(user_input)
|
56 |
+
st.session_state.generated.append(output)
|
57 |
+
|
58 |
if st.session_state['generated']:
|
59 |
+
for i in range(len(st.session_state['generated'])-1, -1, -1):
|
60 |
+
message(st.session_state["generated"][i], key=str(i))
|
61 |
+
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
62 |
+
else:
|
63 |
+
st.warning('wrong key!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|