Spaces:
Runtime error
Runtime error
Crimson206
commited on
Upload folder using huggingface_hub
Browse files
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()
|