Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,6 +46,20 @@ def textGPT(text):
|
|
| 46 |
return chats
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def clear():
|
| 50 |
global messages
|
| 51 |
messages = [{"role": "system", "content": 'You are a helpful technology assistant.'}]
|
|
@@ -53,11 +67,11 @@ def clear():
|
|
| 53 |
|
| 54 |
|
| 55 |
with gr.Blocks() as test:
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
|
| 63 |
text = gr.Interface(fn=textGPT, inputs="text", outputs="text")
|
|
|
|
| 46 |
return chats
|
| 47 |
|
| 48 |
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def textGPT2(chat_history, text):
|
| 52 |
+
global messages
|
| 53 |
+
|
| 54 |
+
messages.append({"role": "user", "content": text})
|
| 55 |
+
|
| 56 |
+
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
|
| 57 |
+
|
| 58 |
+
system_message = response["choices"][0]["message"]
|
| 59 |
+
|
| 60 |
+
return chat_history + [[text, system_message]]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
def clear():
|
| 64 |
global messages
|
| 65 |
messages = [{"role": "system", "content": 'You are a helpful technology assistant.'}]
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
with gr.Blocks() as test:
|
| 70 |
+
chatbot = gr.Chatbot()
|
| 71 |
+
msg = gr.Textbox()
|
| 72 |
+
clear = gr.Button("Clear")
|
| 73 |
+
msg.submit(textGPT2, [chatbot, msg], chatbot)
|
| 74 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 75 |
|
| 76 |
|
| 77 |
text = gr.Interface(fn=textGPT, inputs="text", outputs="text")
|