Crimson206 commited on
Commit
d6e32e0
Β·
verified Β·
1 Parent(s): 69e8120

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app2.py +26 -0
app2.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+ openai.api_key = "sk-..." # Replace with your key
5
+
6
+ def predict(message, history):
7
+ history_openai_format = []
8
+ for human, assistant in history:
9
+ history_openai_format.append({"role": "user", "content": human })
10
+ history_openai_format.append({"role": "assistant", "content":assistant})
11
+ history_openai_format.append({"role": "user", "content": message})
12
+
13
+ response = openai.ChatCompletion.create(
14
+ model='gpt-3.5-turbo',
15
+ messages= history_openai_format,
16
+ temperature=1.0,
17
+ stream=True
18
+ )
19
+
20
+ partial_message = ""
21
+ for chunk in response:
22
+ if len(chunk['choices'][0]['delta']) != 0:
23
+ partial_message = partial_message + chunk['choices'][0]['delta']['content']
24
+ yield partial_message
25
+
26
+ gr.ChatInterface(predict).launch()