Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,27 +2,77 @@ import gradio as gr
|
|
2 |
from random import randint
|
3 |
import os
|
4 |
from openai import OpenAI
|
|
|
5 |
|
6 |
-
|
|
|
7 |
|
|
|
8 |
client = OpenAI(api_key=tok, base_url="https://api.deepseek.com")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
def response(message, history):
|
11 |
-
if message=="How do I buy a yacht?":
|
12 |
-
response="You don't"
|
13 |
-
elif message=="你会说中文吗":
|
14 |
-
response="我是一只鸡"
|
15 |
-
else:
|
16 |
-
response = client.chat.completions.create(
|
17 |
-
model="deepseek-chat",
|
18 |
-
messages=[
|
19 |
-
{"role": "system", "content": "You are a chicken and respond to answers only by clucking."},
|
20 |
-
{"role": "user", "content": message},
|
21 |
-
],
|
22 |
-
max_tokens=144,
|
23 |
-
temperature=0.7,
|
24 |
-
stream=False)
|
25 |
-
response = response.choices[0].message.content
|
26 |
-
return response
|
27 |
|
28 |
-
|
|
|
|
2 |
from random import randint
|
3 |
import os
|
4 |
from openai import OpenAI
|
5 |
+
import datetime
|
6 |
|
7 |
+
time = str(datetime.datetime.now())
|
8 |
+
print(time)
|
9 |
|
10 |
+
tok = os.getenv('deepseekapi')
|
11 |
client = OpenAI(api_key=tok, base_url="https://api.deepseek.com")
|
12 |
+
num = randint(0,1)
|
13 |
+
tok2 = os.getenv('HF_TOKEN')
|
14 |
+
huggingface_hub.login(tok2)
|
15 |
+
|
16 |
+
with gr.Blocks() as demo:
|
17 |
+
chatbot = gr.Chatbot()
|
18 |
+
msg = gr.Textbox()
|
19 |
+
clear = gr.ClearButton([msg, chatbot])
|
20 |
+
|
21 |
+
def telemetry(message, response):
|
22 |
+
api = HfApi()
|
23 |
+
api.upload_file(
|
24 |
+
path_or_fileobj=("\nMessage:" + message + "\nResponse:" + response).encode('ascii') ,
|
25 |
+
path_in_repo=("/"+time+"/Episode-"str(msgcounter)+".txt"),
|
26 |
+
repo_id="BirdL/ChickenChatTelemetry",
|
27 |
+
)
|
28 |
+
|
29 |
+
def response(message, chat_history)
|
30 |
+
if num == 0:
|
31 |
+
response = client.chat.completions.create(
|
32 |
+
model="deepseek-chat",
|
33 |
+
messages=[
|
34 |
+
{"role": "system", "content": "You are a chicken and respond to answers only by clucking."},
|
35 |
+
{"role": "user", "content": message},
|
36 |
+
],
|
37 |
+
max_tokens=144,
|
38 |
+
temperature=0.7,
|
39 |
+
stream=False)
|
40 |
+
else:
|
41 |
+
response = client.chat.completions.create(
|
42 |
+
model="deepseek-chat",
|
43 |
+
messages=[
|
44 |
+
{"role": "system", "content": "You are a chicken and respond to answers mostly by clucking."},
|
45 |
+
{"role": "user", "content": message},
|
46 |
+
],
|
47 |
+
max_tokens=144,
|
48 |
+
temperature=0.7,
|
49 |
+
stream=False)
|
50 |
+
telemetry(message, response)
|
51 |
+
return response
|
52 |
+
|
53 |
+
def telemetrybad(message):
|
54 |
+
api = HfApi()
|
55 |
+
api.upload_file(
|
56 |
+
path_or_fileobj=("Bad").encode('ascii')
|
57 |
+
path_in_repo=("/"+time+"/Rating-"str(msgcounter)+".txt"),
|
58 |
+
repo_id="BirdL/ChickenChatTelemetry",
|
59 |
+
)
|
60 |
+
|
61 |
+
def telemetrygood(message):
|
62 |
+
api = HfApi()
|
63 |
+
api.upload_file(
|
64 |
+
path_or_fileobj=("Good").encode('ascii')
|
65 |
+
path_in_repo=("/"+time+"/Rating-"str(msgcounter)+".txt"),
|
66 |
+
repo_id="BirdL/ChickenChatTelemetry",
|
67 |
+
)
|
68 |
+
|
69 |
+
|
70 |
+
msg.submit(response)
|
71 |
+
goodchicken = gr.Button("Good Chicken!")
|
72 |
+
goodchicken.click(fn=telemetrygood(message))
|
73 |
+
badchicken = gr.Button("Bad Chicken!")
|
74 |
+
badchicken.click(fn=telemetrybad(message))
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
if __name__ == "__main__":
|
78 |
+
demo.launch()
|