Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
from openai import OpenAI
|
| 2 |
-
import gradio as gr
|
| 3 |
-
|
| 4 |
-
api_key = "sk-proj-EDY3jlWEqNq4xkGk0inbT3BlbkFJKbN26l1g02vd16B11Ksb"
|
| 5 |
-
client = OpenAI(api_key=api_key)
|
| 6 |
-
|
| 7 |
-
def predict(message, history):
|
| 8 |
-
history_openai_format = []
|
| 9 |
-
for human, assistant in history:
|
| 10 |
-
history_openai_format.append({"role": "user", "content": human })
|
| 11 |
-
history_openai_format.append({"role": "assistant", "content":assistant})
|
| 12 |
-
history_openai_format.append({"role": "user", "content": message})
|
| 13 |
-
|
| 14 |
-
response = client.chat.completions.create(model='gpt-3.5-turbo',
|
| 15 |
-
messages= history_openai_format,
|
| 16 |
-
temperature=1.0,
|
| 17 |
-
stream=True)
|
| 18 |
-
|
| 19 |
-
partial_message = ""
|
| 20 |
-
for chunk in response:
|
| 21 |
-
if chunk.choices[0].delta.content is not None:
|
| 22 |
-
partial_message = partial_message + chunk.choices[0].delta.content
|
| 23 |
-
yield partial_message
|
| 24 |
-
|
| 25 |
-
gr.ChatInterface(predict).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|