bstraehle commited on
Commit
aa0eed8
1 Parent(s): ac81340

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -1 +1,18 @@
1
- TODO
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()