Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import time
|
| 3 |
|
| 4 |
-
|
| 5 |
-
response = f"System prompt: {system_prompt}\n Message: {message}."
|
| 6 |
-
for i in range(min(len(response), int(tokens))):
|
| 7 |
-
time.sleep(0.05)
|
| 8 |
-
yield response[: i+1]
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
+
openai.api_key = "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" # 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()
|