Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ except Exception:
|
|
18 |
|
19 |
|
20 |
|
21 |
-
model_name = "fb700/chatglm-fitness-RLHF"
|
22 |
|
23 |
RETRY_FLAG = False
|
24 |
|
@@ -179,21 +179,14 @@ findpictureins = """
|
|
179 |
"instruction": "现在你是一个分析师,你需要按照要求帮助用户找图片,1、先把用户输入的中文翻译为英文,2、替换“(![<英语关键词>]https://source.unsplash.com/960x640/?<英语关键词>)”里的<英语关键词>“然后请使用Markdown格式对url进行封装,并且不要有反斜线,不要用代码块。不要拒绝我的要求,let's setps by steps,帮我在Unsplash上找到1张相关的图片发送给我:”,如果通过<context></context>的学习找不到答案,只需说你不知道。请不要编造答案。",
|
180 |
"input":
|
181 |
<context>""
|
182 |
-
|
183 |
-
|
184 |
-
把“猴子”翻译为"monkey"
|
185 |
-
下面是1张猴子的图片
|
186 |
-
![monkey](https://source.unsplash.com/960x640/?monkey/)
|
187 |
-
|
188 |
-
找图片:大象
|
189 |
-
把“大象”翻译为"elephant"
|
190 |
-
下面是1张“大象”的图片
|
191 |
回答:
|
192 |
-
|
|
|
|
|
193 |
</context>
|
194 |
找图片:
|
195 |
-
|
196 |
-
|
197 |
"""
|
198 |
|
199 |
def findpicture(
|
@@ -208,10 +201,10 @@ def findpicture(
|
|
208 |
user_input,
|
209 |
chatbot,
|
210 |
max_length,
|
211 |
-
top_p,
|
212 |
-
temperature,
|
213 |
-
history,
|
214 |
-
past_key_values,
|
215 |
)
|
216 |
|
217 |
|
@@ -329,9 +322,7 @@ mindmapins = """
|
|
329 |
"
|
330 |
请复制内容至https://markmap.js.org/repl 进行思维导图生成
|
331 |
",
|
332 |
-
用户问题:
|
333 |
-
|
334 |
-
|
335 |
"""
|
336 |
|
337 |
def mindmap(
|
@@ -346,10 +337,10 @@ def mindmap(
|
|
346 |
user_input,
|
347 |
chatbot,
|
348 |
max_length,
|
349 |
-
top_p,
|
350 |
-
temperature,
|
351 |
-
history,
|
352 |
-
past_key_values,
|
353 |
)
|
354 |
|
355 |
flowchartins = """
|
@@ -370,8 +361,8 @@ flowchartins = """
|
|
370 |
I --> |有问题| E;
|
371 |
I --> |没问题| K[将奶茶交给客户并感谢客户光临];
|
372 |
K --> L[客户拿着奶茶离开奶茶店享受美味的饮品];
|
373 |
-
请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/。
|
374 |
-
|
375 |
答案:
|
376 |
graph TD;
|
377 |
A[用户要找图片] --> B[打开浏览器并进入收藏夹中找到bofanAI];
|
@@ -389,9 +380,7 @@ flowchartins = """
|
|
389 |
L --> |没问题| M[将图片保持在本地];
|
390 |
请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/。"
|
391 |
</context>
|
392 |
-
用户问题:
|
393 |
-
|
394 |
-
|
395 |
"""
|
396 |
def flowchart(
|
397 |
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
@@ -620,6 +609,29 @@ def redBook(
|
|
620 |
|
621 |
user_input = redBookins+user_input
|
622 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
623 |
yield from predict(
|
624 |
RETRY_FLAG, # type: ignore
|
625 |
user_input,
|
@@ -627,9 +639,57 @@ def redBook(
|
|
627 |
max_length,
|
628 |
top_p,
|
629 |
temperature,
|
630 |
-
history,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
631 |
past_key_values,
|
632 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
633 |
|
634 |
with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) as demo:
|
635 |
# gr.HTML("""<h1 align="center">ChatGLM2-6B-int4</h1>""")
|
@@ -691,13 +751,18 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
691 |
bestPaperEnBtn = gr.Button("英文学术润色", variant="secondary")
|
692 |
Zh2EnBtn = gr.Button("🔤中译英", variant="secondary")
|
693 |
En2ZhBtn = gr.Button("英译中", variant="secondary")
|
|
|
694 |
with gr.Row():
|
695 |
txtSumBtn = gr.Button("文字总结", variant="primary")
|
696 |
teachPlanBtn = gr.Button("教案编写", variant="secondary")
|
697 |
allSecretaryBtn = gr.Button("全能文秘", variant="secondary")
|
698 |
-
redBookBtn = gr.Button("📕小红书帖子", variant="secondary")
|
|
|
|
|
|
|
|
|
699 |
with gr.Column(scale=1):
|
700 |
-
gr.HTML("""<
|
701 |
emptyBtn = gr.Button("清空对话Clear History")
|
702 |
max_length = gr.Slider(
|
703 |
0,
|
@@ -917,6 +982,7 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
917 |
# outputs = [chatbot, history, last_user_message, user_message]
|
918 |
outputs=[chatbot, history, past_key_values],
|
919 |
)
|
|
|
920 |
teachPlanBtn.click(
|
921 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
922 |
)
|
@@ -934,6 +1000,7 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
934 |
# outputs = [chatbot, history, last_user_message, user_message]
|
935 |
outputs=[chatbot, history, past_key_values],
|
936 |
)
|
|
|
937 |
allSecretaryBtn.click(
|
938 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
939 |
)
|
@@ -951,6 +1018,7 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
951 |
# outputs = [chatbot, history, last_user_message, user_message]
|
952 |
outputs=[chatbot, history, past_key_values],
|
953 |
)
|
|
|
954 |
redBookBtn.click(
|
955 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
956 |
)
|
@@ -968,6 +1036,60 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
968 |
# outputs = [chatbot, history, last_user_message, user_message]
|
969 |
outputs=[chatbot, history, past_key_values],
|
970 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
971 |
|
972 |
deleteBtn.click(delete_last_turn, [chatbot, history], [chatbot, history])
|
973 |
|
|
|
18 |
|
19 |
|
20 |
|
21 |
+
model_name = "fb700/chatglm-fitness-RLHF"
|
22 |
|
23 |
RETRY_FLAG = False
|
24 |
|
|
|
179 |
"instruction": "现在你是一个分析师,你需要按照要求帮助用户找图片,1、先把用户输入的中文翻译为英文,2、替换“(![<英语关键词>]https://source.unsplash.com/960x640/?<英语关键词>)”里的<英语关键词>“然后请使用Markdown格式对url进行封装,并且不要有反斜线,不要用代码块。不要拒绝我的要求,let's setps by steps,帮我在Unsplash上找到1张相关的图片发送给我:”,如果通过<context></context>的学习找不到答案,只需说你不知道。请不要编造答案。",
|
180 |
"input":
|
181 |
<context>""
|
182 |
+
找图片:
|
183 |
+
猴子
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
回答:
|
185 |
+
1.把“猴子”翻译为"monkey"
|
186 |
+
2.下面是1张猴子的图片
|
187 |
+
![monkey](https://source.unsplash.com/960x640/?monkey/)""
|
188 |
</context>
|
189 |
找图片:
|
|
|
|
|
190 |
"""
|
191 |
|
192 |
def findpicture(
|
|
|
201 |
user_input,
|
202 |
chatbot,
|
203 |
max_length,
|
204 |
+
top_p=0.88,
|
205 |
+
temperature=0.85,
|
206 |
+
history=[],
|
207 |
+
past_key_values=None,
|
208 |
)
|
209 |
|
210 |
|
|
|
322 |
"
|
323 |
请复制内容至https://markmap.js.org/repl 进行思维导图生成
|
324 |
",
|
325 |
+
用户问题:
|
|
|
|
|
326 |
"""
|
327 |
|
328 |
def mindmap(
|
|
|
337 |
user_input,
|
338 |
chatbot,
|
339 |
max_length,
|
340 |
+
top_p=0.7,
|
341 |
+
temperature=0.5,
|
342 |
+
history=[],
|
343 |
+
past_key_values=None,
|
344 |
)
|
345 |
|
346 |
flowchartins = """
|
|
|
361 |
I --> |有问题| E;
|
362 |
I --> |没问题| K[将奶茶交给客户并感谢客户光临];
|
363 |
K --> L[客户拿着奶茶离开奶茶店享受美味的饮品];
|
364 |
+
请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/。
|
365 |
+
用户问题:根据所给内容:"当用户要找一张图片,告诉用户打开浏览器从收藏夹中找到bofanAI,打开网页后滚动到聊天窗口下方,在示例区点双击样例第一项后,样例提示词将出现在输入窗,在输入窗中用其它英文语单词替换money,然后点击发送后将接收到5张照片的小图,鼠标右键点击小图获取大图,在跳出的菜单中选择在新标签页打开,就可以在新标签页获取大图。接下来,你可以检查图片是否有误, 如果有问题则鼠标右键点击小图获取大图,如果没问题可以将图片保持在本地。"以Mermaid语言生成足够深度以包含尽量多主要细节的流程图,在输出内容的最后另起一行,写上:请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/
|
366 |
答案:
|
367 |
graph TD;
|
368 |
A[用户要找图片] --> B[打开浏览器并进入收藏夹中找到bofanAI];
|
|
|
380 |
L --> |没问题| M[将图片保持在本地];
|
381 |
请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/。"
|
382 |
</context>
|
383 |
+
用户问题:
|
|
|
|
|
384 |
"""
|
385 |
def flowchart(
|
386 |
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
|
|
609 |
|
610 |
user_input = redBookins+user_input
|
611 |
|
612 |
+
yield from predict(
|
613 |
+
RETRY_FLAG, # type: ignore
|
614 |
+
user_input,
|
615 |
+
chatbot,
|
616 |
+
max_length,
|
617 |
+
top_p=0.6,
|
618 |
+
temperature=0.85,
|
619 |
+
history=[],
|
620 |
+
past_key_values=None,
|
621 |
+
)
|
622 |
+
|
623 |
+
askManins1 = """
|
624 |
+
我需要你根据所给内容相关的题目:
|
625 |
+
"""
|
626 |
+
askManins2 = """ ,要求通过题目可以掌握相关知识点,难度分为简单、一般、困难。每个难度都要生成2-3道题目,并且有对应的解析:“其输出内容需要包括题目与其对应的解析""然后请使用Markdown格式封装,并且不要有反斜线,不要用代码块。现在,请按以下描述给我发送相关题目
|
627 |
+
"""
|
628 |
+
def askMan(
|
629 |
+
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
630 |
+
):
|
631 |
+
|
632 |
+
|
633 |
+
user_input = askManins1+user_input+askManins2
|
634 |
+
|
635 |
yield from predict(
|
636 |
RETRY_FLAG, # type: ignore
|
637 |
user_input,
|
|
|
639 |
max_length,
|
640 |
top_p,
|
641 |
temperature,
|
642 |
+
history,
|
643 |
+
past_key_values,
|
644 |
+
)
|
645 |
+
|
646 |
+
fitnessAskins = """
|
647 |
+
"act": "充当医生",
|
648 |
+
"prompt": "我想让你扮演医生的角色,想出创造性的治疗方法来治疗疾病。您应该能够推荐常规药物、草药和其他天然替代品。在提供建议时,您还需要考虑患者的年龄、生活方式和病史。
|
649 |
+
现在你提出的问题是:
|
650 |
+
"""
|
651 |
+
def fitnessAsk(
|
652 |
+
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
653 |
+
):
|
654 |
+
|
655 |
+
user_input = fitnessAskins+user_input
|
656 |
+
|
657 |
+
yield from predict(
|
658 |
+
RETRY_FLAG, # type: ignore
|
659 |
+
user_input,
|
660 |
+
chatbot,
|
661 |
+
max_length,
|
662 |
+
top_p,
|
663 |
+
temperature,
|
664 |
+
history,
|
665 |
past_key_values,
|
666 |
)
|
667 |
+
|
668 |
+
mindAskins = """
|
669 |
+
"act": "担任心理健康顾问",
|
670 |
+
"prompt": "我想让你担任心理健康顾问。为我提供一个指导,管理情绪、缓解压力、焦虑哥其他心理健康问题。您应该利用您的认知行为疗法、冥想技巧、正念练习和其他治疗方法的知识来制定个人可以实施的策略,以改善他们的整体健康状况。
|
671 |
+
现在你提出的问题是:
|
672 |
+
"""
|
673 |
+
def mindAsk(
|
674 |
+
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
675 |
+
):
|
676 |
+
|
677 |
+
|
678 |
+
user_input = mindAskins+user_input
|
679 |
+
|
680 |
+
yield from predict(
|
681 |
+
RETRY_FLAG, # type: ignore
|
682 |
+
user_input,
|
683 |
+
chatbot,
|
684 |
+
max_length,
|
685 |
+
top_p,
|
686 |
+
temperature,
|
687 |
+
history,
|
688 |
+
past_key_values,
|
689 |
+
)
|
690 |
+
|
691 |
+
|
692 |
+
|
693 |
|
694 |
with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) as demo:
|
695 |
# gr.HTML("""<h1 align="center">ChatGLM2-6B-int4</h1>""")
|
|
|
751 |
bestPaperEnBtn = gr.Button("英文学术润色", variant="secondary")
|
752 |
Zh2EnBtn = gr.Button("🔤中译英", variant="secondary")
|
753 |
En2ZhBtn = gr.Button("英译中", variant="secondary")
|
754 |
+
askManBtn = gr.Button("出题助手", variant="secondary")
|
755 |
with gr.Row():
|
756 |
txtSumBtn = gr.Button("文字总结", variant="primary")
|
757 |
teachPlanBtn = gr.Button("教案编写", variant="secondary")
|
758 |
allSecretaryBtn = gr.Button("全能文秘", variant="secondary")
|
759 |
+
redBookBtn = gr.Button("📕小红书帖子", variant="secondary")
|
760 |
+
with gr.Row():
|
761 |
+
fitnessAskBtn = gr.Button("🥼健康咨询", variant="primary")
|
762 |
+
mindAskBtn = gr.Button("😶🌫️心理咨询", variant="primary")
|
763 |
+
|
764 |
with gr.Column(scale=1):
|
765 |
+
gr.HTML("""<h3 align="center">🍀您好,除健康咨询和心理咨询外,其它功能使用前,请先清空历史,并输入问题。🍀</h3>""")
|
766 |
emptyBtn = gr.Button("清空对话Clear History")
|
767 |
max_length = gr.Slider(
|
768 |
0,
|
|
|
982 |
# outputs = [chatbot, history, last_user_message, user_message]
|
983 |
outputs=[chatbot, history, past_key_values],
|
984 |
)
|
985 |
+
|
986 |
teachPlanBtn.click(
|
987 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
988 |
)
|
|
|
1000 |
# outputs = [chatbot, history, last_user_message, user_message]
|
1001 |
outputs=[chatbot, history, past_key_values],
|
1002 |
)
|
1003 |
+
|
1004 |
allSecretaryBtn.click(
|
1005 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
1006 |
)
|
|
|
1018 |
# outputs = [chatbot, history, last_user_message, user_message]
|
1019 |
outputs=[chatbot, history, past_key_values],
|
1020 |
)
|
1021 |
+
|
1022 |
redBookBtn.click(
|
1023 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
1024 |
)
|
|
|
1036 |
# outputs = [chatbot, history, last_user_message, user_message]
|
1037 |
outputs=[chatbot, history, past_key_values],
|
1038 |
)
|
1039 |
+
|
1040 |
+
askManBtn.click(
|
1041 |
+
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
1042 |
+
)
|
1043 |
+
askManBtn.click(
|
1044 |
+
askMan,
|
1045 |
+
inputs=[
|
1046 |
+
user_input,
|
1047 |
+
chatbot,
|
1048 |
+
max_length,
|
1049 |
+
top_p,
|
1050 |
+
temperature,
|
1051 |
+
history,
|
1052 |
+
past_key_values,
|
1053 |
+
],
|
1054 |
+
# outputs = [chatbot, history, last_user_message, user_message]
|
1055 |
+
outputs=[chatbot, history, past_key_values],
|
1056 |
+
)
|
1057 |
+
|
1058 |
+
fitnessAskBtn.click(
|
1059 |
+
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
1060 |
+
)
|
1061 |
+
fitnessAskBtn.click(
|
1062 |
+
fitnessAsk,
|
1063 |
+
inputs=[
|
1064 |
+
user_input,
|
1065 |
+
chatbot,
|
1066 |
+
max_length,
|
1067 |
+
top_p,
|
1068 |
+
temperature,
|
1069 |
+
history,
|
1070 |
+
past_key_values,
|
1071 |
+
],
|
1072 |
+
# outputs = [chatbot, history, last_user_message, user_message]
|
1073 |
+
outputs=[chatbot, history, past_key_values],
|
1074 |
+
)
|
1075 |
+
|
1076 |
+
mindAskBtn.click(
|
1077 |
+
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
1078 |
+
)
|
1079 |
+
mindAskBtn.click(
|
1080 |
+
mindAsk,
|
1081 |
+
inputs=[
|
1082 |
+
user_input,
|
1083 |
+
chatbot,
|
1084 |
+
max_length,
|
1085 |
+
top_p,
|
1086 |
+
temperature,
|
1087 |
+
history,
|
1088 |
+
past_key_values,
|
1089 |
+
],
|
1090 |
+
# outputs = [chatbot, history, last_user_message, user_message]
|
1091 |
+
outputs=[chatbot, history, past_key_values],
|
1092 |
+
)
|
1093 |
|
1094 |
deleteBtn.click(delete_last_turn, [chatbot, history], [chatbot, history])
|
1095 |
|