Spaces:
Runtime error
Runtime error
Commit
·
ccec9b3
1
Parent(s):
88b3475
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,9 @@ import random
|
|
| 7 |
import time
|
| 8 |
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
PRESET_ANSWERS = ["刚到美国的时候,觉得美国人像傻子一样,到处都是漏洞。任何地方的厕所都有免费纸,有些人定期去扯很多回家,纸都不用买。快餐店的饮料,有的可以无限续杯,有些几个人买一份饮料,接回来灌到各自的杯子里;等等。",
|
| 11 |
"尽管美国有许多“漏洞”,但作为超级大国,显然能带给人以无尽的故事与思考。我来分享一下哪些是去了美国才知道的事,主题主要围绕着生活、衣食住行、文化冲击、教育医疗等展开叙说,本文有5千字左右,你也可以跳到感兴趣的部分阅读。"
|
| 12 |
"美国的城市风貌与基础设施1、去到了美国才知道,纽约的城市样貌跟我想象的发达不一样,真实的纽约街景是很嘈杂和市井。例如,在曼哈顿区路旁,随处可见的小摊位,卖鲜花的、卖各种小食、卖自制首饰的,卖艺术品等等。我留意一下,发现每个路边摊都有合法的营业执照。"]
|
|
@@ -33,16 +36,36 @@ def get_chat_answer(query, chatbot):
|
|
| 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"
|
| 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"
|
| 46 |
with gr.Row():
|
| 47 |
with gr.Column():
|
| 48 |
ft_task_name = gr.Textbox(value="", label="任务名称")
|
|
@@ -51,7 +74,8 @@ with gr.Blocks(css=css) as demo:
|
|
| 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 |
-
|
|
|
|
| 55 |
gr.Markdown(METRICS_TAB_TEXT, elem_classes="markdown-text")
|
| 56 |
|
| 57 |
demo.queue(max_size=20).launch()
|
|
|
|
| 7 |
import time
|
| 8 |
|
| 9 |
|
| 10 |
+
handshake_url = "http://127.0.0.1:8000/chatbot/"
|
| 11 |
+
dialog_url = "http://127.0.0.1:8000/chatbot/dialoginfo"
|
| 12 |
+
finish_query_url = "http://127.0.0.1:8000/chatbot/finishquery"
|
| 13 |
PRESET_ANSWERS = ["刚到美国的时候,觉得美国人像傻子一样,到处都是漏洞。任何地方的厕所都有免费纸,有些人定期去扯很多回家,纸都不用买。快餐店的饮料,有的可以无限续杯,有些几个人买一份饮料,接回来灌到各自的杯子里;等等。",
|
| 14 |
"尽管美国有许多“漏洞”,但作为超级大国,显然能带给人以无尽的故事与思考。我来分享一下哪些是去了美国才知道的事,主题主要围绕着生活、衣食住行、文化冲击、教育医疗等展开叙说,本文有5千字左右,你也可以跳到感兴趣的部分阅读。"
|
| 15 |
"美国的城市风貌与基础设施1、去到了美国才知道,纽约的城市样貌跟我想象的发达不一样,真实的纽约街景是很嘈杂和市井。例如,在曼哈顿区路旁,随处可见的小摊位,卖鲜花的、卖各种小食、卖自制首饰的,卖艺术品等等。我留意一下,发现每个路边摊都有合法的营业执照。"]
|
|
|
|
| 36 |
yield "", chatbot
|
| 37 |
|
| 38 |
|
| 39 |
+
def get_chat_answer_request(query, chatbot):
|
| 40 |
+
q_id = str(uuid.uuid1())
|
| 41 |
+
r = requests.post(handshake_url, json={"q_id": q_id, "query": query, 'history': chatbot})
|
| 42 |
+
if r.json()['code'] == 202:
|
| 43 |
+
for _ in range(1000):
|
| 44 |
+
r = requests.get(dialog_url, {"dialogid": q_id})
|
| 45 |
+
history = r.json()['history']
|
| 46 |
+
print(history)
|
| 47 |
+
while len(history[-1]) == 0:
|
| 48 |
+
history.pop()
|
| 49 |
+
r_finish = requests.get(finish_query_url, {"dialogid": q_id})
|
| 50 |
+
if r_finish.json() == True:
|
| 51 |
+
yield "", history
|
| 52 |
+
print('break')
|
| 53 |
+
break
|
| 54 |
+
|
| 55 |
+
yield "", history
|
| 56 |
+
time.sleep(1)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
css = """
|
| 60 |
col-container {max-width: 510px; margin-left: auto; margin-right: auto; margin-up: auto; margin-bottom: auto;}
|
| 61 |
"""
|
| 62 |
with gr.Blocks(css=css) as demo:
|
| 63 |
with gr.Column(elem_id="col-container"):
|
| 64 |
+
with gr.Tab("🧠 模型对话 Dialog"):
|
| 65 |
chatbot = gr.Chatbot([[None, get_internet_ip()]], show_label=False, elem_id="chatbot")
|
| 66 |
query = gr.Textbox(show_label=False, placeholder="请输入提问内容,按回车进行提交")
|
| 67 |
query.submit(get_chat_answer,[query, chatbot], [query, chatbot])
|
| 68 |
+
with gr.Tab("🎚️ 模型微调 Fine-tune"):
|
| 69 |
with gr.Row():
|
| 70 |
with gr.Column():
|
| 71 |
ft_task_name = gr.Textbox(value="", label="任务名称")
|
|
|
|
| 74 |
ft_epochs = gr.Textbox(value="", label="epochs")
|
| 75 |
ft_start_lr = gr.Textbox(value="", label="start LR")
|
| 76 |
ft_end_lr = gr.Textbox(value="", label="end LR")
|
| 77 |
+
submit_btn = gr.Button(value="Submit")
|
| 78 |
+
with gr.Tab("📈 信息 Info"):
|
| 79 |
gr.Markdown(METRICS_TAB_TEXT, elem_classes="markdown-text")
|
| 80 |
|
| 81 |
demo.queue(max_size=20).launch()
|