Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1 +1,18 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
|
4 |
+
client = openai.OpenAI(api_key = os.getenv("OPENAI_API_KEY"))
|
5 |
+
threads = {}
|
6 |
+
|
7 |
+
def predict(message, history, request: gr.Request):
|
8 |
+
if request.session_hash in threads:
|
9 |
+
thread = threads[request.session_hash]
|
10 |
+
else:
|
11 |
+
threads[request.session_hash] = client.beta.threads.create()
|
12 |
+
|
13 |
+
message = client.beta.threads.messages.create(
|
14 |
+
thread_id=thread.id,
|
15 |
+
role="user",
|
16 |
+
content=message)
|
17 |
+
|
18 |
+
gr.ChatInterface(predict).launch()
|