Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ import gradio as gr
|
|
11 |
import os
|
12 |
|
13 |
from assistants import (
|
|
|
14 |
set_openai_client,
|
15 |
get_assistant,
|
16 |
set_assistant,
|
@@ -33,19 +34,15 @@ def chat(message, history, openai_api_key):
|
|
33 |
raise gr.Error("OpenAI API Key is required (see additional inputs below).")
|
34 |
if not message:
|
35 |
raise gr.Error("Message is required.")
|
|
|
|
|
|
|
36 |
|
37 |
-
global assistant, thread
|
38 |
-
|
39 |
-
# On first run, create assistant and update assistant_id,
|
40 |
-
# see https://platform.openai.com/playground/assistants.
|
41 |
-
# On subsequent runs, load assistant.
|
42 |
if get_assistant() == None:
|
43 |
#set_assistant(create_assistant())
|
44 |
set_assistant(load_assistant())
|
45 |
|
46 |
-
# TODO: Use Gradio session to support multiple users
|
47 |
if get_thread == None or len(history) == 0:
|
48 |
-
set_openai_client(openai_api_key)
|
49 |
set_thread(create_thread())
|
50 |
|
51 |
create_message(get_thread(), message)
|
@@ -62,8 +59,8 @@ def chat(message, history, openai_api_key):
|
|
62 |
if len(image_values) > 0:
|
63 |
download_link = f"<hr>[Download](https://platform.openai.com/storage/files/{image_values[0]})"
|
64 |
|
65 |
-
|
66 |
-
return f"{text_values[0]}{download_link}"
|
67 |
|
68 |
gr.ChatInterface(
|
69 |
fn=chat,
|
|
|
11 |
import os
|
12 |
|
13 |
from assistants import (
|
14 |
+
get_openai_client,
|
15 |
set_openai_client,
|
16 |
get_assistant,
|
17 |
set_assistant,
|
|
|
34 |
raise gr.Error("OpenAI API Key is required (see additional inputs below).")
|
35 |
if not message:
|
36 |
raise gr.Error("Message is required.")
|
37 |
+
|
38 |
+
if get_openai_client() == None:
|
39 |
+
set_openai_client(openai_api_key)
|
40 |
|
|
|
|
|
|
|
|
|
|
|
41 |
if get_assistant() == None:
|
42 |
#set_assistant(create_assistant())
|
43 |
set_assistant(load_assistant())
|
44 |
|
|
|
45 |
if get_thread == None or len(history) == 0:
|
|
|
46 |
set_thread(create_thread())
|
47 |
|
48 |
create_message(get_thread(), message)
|
|
|
59 |
if len(image_values) > 0:
|
60 |
download_link = f"<hr>[Download](https://platform.openai.com/storage/files/{image_values[0]})"
|
61 |
|
62 |
+
return f"{'<hr>'.join(list(reversed(text_values))[1:])}{download_link}"
|
63 |
+
#return f"{text_values[0]}{download_link}"
|
64 |
|
65 |
gr.ChatInterface(
|
66 |
fn=chat,
|