Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -34,35 +34,53 @@ def history_gradio2gpt(gradio_history):
|
|
34 |
return gpt_history
|
35 |
|
36 |
|
37 |
-
|
38 |
-
chat_history = []
|
39 |
-
|
40 |
with gr.Blocks() as demo:
|
41 |
-
|
42 |
-
|
43 |
-
clear = gr.
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
|
68 |
|
|
|
34 |
return gpt_history
|
35 |
|
36 |
|
|
|
|
|
|
|
37 |
with gr.Blocks() as demo:
|
38 |
+
chatbot_blk = gr.Chatbot(label="Chat")
|
39 |
+
input_blk = gr.Textbox(lines=1, label="Message", placeholder="Type your message here")
|
40 |
+
clear = gr.ClearButton([input_blk, chatbot_blk])
|
41 |
+
|
42 |
+
def respond(input_text, gradio_history):
|
43 |
+
if gradio_history is not None:
|
44 |
+
gpt_history = history_gradio2gpt(gradio_history)
|
45 |
+
|
46 |
+
output_text = gpt4(input_text,gpt_history)
|
47 |
+
gradio_history.append((input_text,output_text))
|
48 |
+
gpt_history = history_gradio2gpt(gradio_history)
|
49 |
+
ask_for_suggestion = "Based on the above conversation, please suggest my next message. Give just the message and nothing else."
|
50 |
+
prompt_suggestion = gpt4(ask_for_suggestion,gpt_history)
|
51 |
+
|
52 |
+
return prompt_suggestion, gradio_history
|
53 |
+
|
54 |
+
input_blk.submit(respond, [input_blk, chatbot_blk], [input_blk, chatbot_blk])
|
55 |
+
|
56 |
+
# chat_history = []
|
57 |
+
|
58 |
+
# with gr.Blocks() as demo:
|
59 |
+
# chatbot = gr.Chatbot()
|
60 |
+
# msg = gr.Textbox()
|
61 |
+
# clear = gr.Button("Clear")
|
62 |
+
|
63 |
+
|
64 |
+
# print("chat_history")
|
65 |
+
# def user(user_message, history):
|
66 |
+
# chat_history.append({"role":"user","content":user_message})
|
67 |
+
# return "", history + [[user_message, None]]
|
68 |
+
|
69 |
+
# def bot(history):
|
70 |
+
# bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
71 |
+
# chat_history.append({"role":"assistant","content":bot_message})
|
72 |
+
# history[-1][1] = ""
|
73 |
+
# with open('chatbot.json', 'w') as f:
|
74 |
+
# json.dump(chat_history, f)
|
75 |
+
# for character in bot_message:
|
76 |
+
# history[-1][1] += character
|
77 |
+
# time.sleep(0.05)
|
78 |
+
# yield history
|
79 |
+
|
80 |
+
# msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False, api_name="chat").then(
|
81 |
+
# bot, chatbot, chatbot
|
82 |
+
# )
|
83 |
+
# clear.click(lambda: None, None, chatbot, queue=False, api_name="clear")
|
84 |
|
85 |
|
86 |
|