Spaces:
Sleeping
Sleeping
kumshing-wilson-huang
commited on
Commit
•
11306b3
1
Parent(s):
966a7c3
init
Browse files- README.md +1 -1
- app.py +23 -6
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 🦀
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
|
|
1 |
---
|
2 |
+
title: HelloWorld
|
3 |
emoji: 🦀
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
app.py
CHANGED
@@ -1,10 +1,27 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import time
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
return f"You uploaded {num_files} files"
|
7 |
|
8 |
-
demo = gr.ChatInterface(fn=count_files, examples=[{"text": "Hello", "files": []}], title="Echo Bot", multimodal=True)
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openai import OpenAI
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
api_key = "sk-proj-KyHyIzEDLKe94DhrSq6LT3BlbkFJynj2NRPnnRwdDSV3XaZY" # Replace with your key
|
5 |
+
client = OpenAI(api_key=api_key)
|
|
|
6 |
|
|
|
7 |
|
8 |
+
def predict(message, history):
|
9 |
+
history_openai_format = []
|
10 |
+
for human, assistant in history:
|
11 |
+
history_openai_format.append({"role": "user", "content": human})
|
12 |
+
history_openai_format.append({"role": "assistant", "content": assistant})
|
13 |
+
history_openai_format.append({"role": "user", "content": message})
|
14 |
+
|
15 |
+
response = client.chat.completions.create(model='gpt-3.5-turbo',
|
16 |
+
messages=history_openai_format,
|
17 |
+
temperature=1.0,
|
18 |
+
stream=True)
|
19 |
+
|
20 |
+
partial_message = ""
|
21 |
+
for chunk in response:
|
22 |
+
if chunk.choices[0].delta.content is not None:
|
23 |
+
partial_message = partial_message + chunk.choices[0].delta.content
|
24 |
+
yield partial_message
|
25 |
+
|
26 |
+
|
27 |
+
gr.ChatInterface(predict).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
openai
|