Spaces:
Runtime error
Runtime error
Commit
·
83019fb
1
Parent(s):
cd853d6
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,16 @@
|
|
1 |
-
import requests
|
2 |
import gradio as gr
|
3 |
-
import
|
|
|
4 |
import re
|
5 |
import uuid
|
6 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
handshake_url = os.environ['HANDSHAKE_URL']
|
9 |
-
dialog_url = os.environ['DIALOG_URL']
|
10 |
-
finish_query_url = os.environ['FINISH_QUERY_URL']
|
11 |
|
12 |
def get_internet_ip():
|
13 |
r = requests.get("http://txt.go.sohu.com/ip/soip")
|
@@ -17,30 +20,38 @@ def get_internet_ip():
|
|
17 |
return None
|
18 |
|
19 |
|
20 |
-
def
|
|
|
21 |
q_id = str(uuid.uuid1())
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from constants import METRICS_TAB_TEXT
|
3 |
+
import requests
|
4 |
import re
|
5 |
import uuid
|
6 |
+
import random
|
7 |
+
import time
|
8 |
+
|
9 |
+
|
10 |
+
PRESET_ANSWERS = ["刚到美国的时候,觉得美国人像傻子一样,到处都是漏洞。任何地方的厕所都有免费纸,有些人定期去扯很多回家,纸都不用买。快餐店的饮料,有的可以无限续杯,有些几个人买一份饮料,接回来灌到各自的杯子里;等等。",
|
11 |
+
"尽管美国有许多“漏洞”,但作为超级大国,显然能带给人以无尽的故事与思考。我来分享一下哪些是去了美国才知道的事,主题主要围绕着生活、衣食住行、文化冲击、教育医疗等展开叙说,本文有5千字左右,你也可以跳到感兴趣的部分阅读。"
|
12 |
+
"美国的城市风貌与基础设施1、去到了美国才知道,纽约的城市样貌跟我想象的发达不一样,真实的纽约街景是很嘈杂和市井。例如,在曼哈顿区路旁,随处可见的小摊位,卖鲜花的、卖各种小食、卖自制首饰的,卖艺术品等等。我留意一下,发现每个路边摊都有合法的营业执照。"]
|
13 |
|
|
|
|
|
|
|
14 |
|
15 |
def get_internet_ip():
|
16 |
r = requests.get("http://txt.go.sohu.com/ip/soip")
|
|
|
20 |
return None
|
21 |
|
22 |
|
23 |
+
def get_chat_answer(query, chatbot):
|
24 |
+
chatbot.append([query, ""])
|
25 |
q_id = str(uuid.uuid1())
|
26 |
+
this_answer = random.choice(PRESET_ANSWERS)
|
27 |
+
for i in range(0, len(this_answer), 3):
|
28 |
+
time.sleep(0.5)
|
29 |
+
print(uuid.uuid1())
|
30 |
+
chatbot[-1][-1] = this_answer[:i] + "▌"
|
31 |
+
yield "", chatbot
|
32 |
+
chatbot[-1][-1] = this_answer
|
33 |
+
yield "", chatbot
|
34 |
+
|
35 |
+
|
36 |
+
css = """
|
37 |
+
col-container {max-width: 510px; margin-left: auto; margin-right: auto; margin-up: auto; margin-bottom: auto;}
|
38 |
+
"""
|
39 |
+
with gr.Blocks(css=css) as demo:
|
40 |
+
with gr.Column(elem_id="col-container"):
|
41 |
+
with gr.Tab("🧠 模型对话 Dialog", elem_id="od-benchmark-tab-table"):
|
42 |
+
chatbot = gr.Chatbot([[None, get_internet_ip()]], show_label=False, elem_id="chatbot")
|
43 |
+
query = gr.Textbox(show_label=False, placeholder="请输入提问内容,按回车进行提交")
|
44 |
+
query.submit(get_chat_answer,[query, chatbot], [query, chatbot])
|
45 |
+
with gr.Tab("🎚️ 模型微调 Fine-tune", elem_id="od-benchmark-tab-table"):
|
46 |
+
with gr.Row():
|
47 |
+
with gr.Column():
|
48 |
+
ft_task_name = gr.Textbox(value="", label="任务名称")
|
49 |
+
ft_task_type = gr.Dropdown(["cat", "dog", "bird"], label="任务类型", info="要创建任务的类型")
|
50 |
+
with gr.Column():
|
51 |
+
ft_epochs = gr.Textbox(value="", label="epochs")
|
52 |
+
ft_start_lr = gr.Textbox(value="", label="start LR")
|
53 |
+
ft_end_lr = gr.Textbox(value="", label="end LR")
|
54 |
+
with gr.Tab("📈 信息 Info", elem_id="od-benchmark-tab-table"):
|
55 |
+
gr.Markdown(METRICS_TAB_TEXT, elem_classes="markdown-text")
|
56 |
+
|
57 |
+
demo.queue(max_size=20).launch(server_port=8080)
|