fb700 commited on
Commit
2c5b1d7
1 Parent(s): a0f9062

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -38
app.py CHANGED
@@ -23,8 +23,8 @@ model_name = "fb700/chatglm-fitness-RLHF"
23
  RETRY_FLAG = False
24
 
25
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
26
- model = AutoModel.from_pretrained(model_name, trust_remote_code=True).quantize(8).half().cuda()
27
- #model = AutoModel.from_pretrained(model_name, trust_remote_code=True).half().cuda()
28
  model = model.eval()
29
 
30
  _ = """Override Chatbot.postprocess"""
@@ -331,8 +331,8 @@ def mindmap(
331
  flowchartins = """
332
  "instruction": "现在你是一个分析师,你需要按照要求将我给你的内容或者主题以Mermaid语言生成足够深度以包含尽量多主要细节的流程图。学习下面的<context></context>里面的知识来完成分析。如果通过<context></context>的学习找不到答案,只需说你不知道。请不要编造答案。",
333
  "input":
334
- <context>
335
- 用户问题:购买奶茶
336
  答案:
337
  graph TD;
338
  A[客户进入奶茶店] --> B[浏览店内菜单并选择奶茶口味和大小];
@@ -346,24 +346,7 @@ flowchartins = """
346
  I --> |有问题| E;
347
  I --> |没问题| K[将奶茶交给客户并感谢客户光临];
348
  K --> L[客户拿着奶茶离开奶茶店享受美味的饮品];
349
- 请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/
350
-
351
- 用户问题:训练一只狗
352
- 答案:
353
- graph TD;
354
- A[狗主人] --> B[给狗喂食+散步+洗澡];
355
- B --> C[训练狗学习新技能];
356
- C --> D[让狗参加社交活动];
357
- D --> E[给狗提供良好的生活环境];
358
- E --> F[让狗保持积极的心态];
359
- F --> G[训练狗遵守指令];
360
- G --> H[让狗遵守指令并听从指挥];
361
- H --> I[检查狗的行为];
362
- I --> |有问题| J[调整训练方法];
363
- J --> G
364
- I --> |没问题| K[奖励狗的行为];
365
- 请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/
366
-
367
  用户问题:根据所给内容:"当用户要找一张图片,告诉用户打开浏览器从收藏夹中找到bofanAI,打开网页后滚动到聊天窗口下方,在示例区点双击样例第一项后,样例提示词将出现在输入窗,在输入窗中用其它英文语单词替换monkey,然后点击发送后将接收到5张照片的小图,鼠标右键点击小图获取大图,在跳出的菜单中选择在新标签页打开,就可以在新标签页获取大图。接下来,你可以检查图片是否有误, 如果有问题则鼠标右键点击小图获取大图,如果没问题可以将图片保持在本地。"
368
  答案:
369
  graph TD;
@@ -380,7 +363,7 @@ flowchartins = """
380
  K --> L[检查图片是否有误];
381
  L --> |有问题| I[鼠标右键点击小图获取大图];
382
  L --> |没问题| M[将图片保持在本地];
383
- 请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/
384
  </context>
385
  用户问题:
386
  """
@@ -573,7 +556,7 @@ def allSecretary(
573
  history,
574
  past_key_values,
575
  )
576
-
577
  redBookins = """
578
  1、如果用户没有输入,请你告诉他:请输入你想写的内容
579
  2、收到用户输入,按照下面是小红书帖子进行编写:
@@ -604,12 +587,14 @@ redBookins = """
604
  用户输入:
605
 
606
  """
 
 
607
  def redBook(
608
  user_input, chatbot, max_length, top_p, temperature, history, past_key_values
609
  ):
610
 
611
-
612
- user_input = redBookins+user_input
613
 
614
  yield from predict(
615
  RETRY_FLAG, # type: ignore
@@ -690,17 +675,55 @@ def mindAsk(
690
  past_key_values,
691
  )
692
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
693
  from bs4 import BeautifulSoup
694
  import requests
695
 
 
696
  def scrape_text(url, proxies) -> str:
697
- """从网页抓取文本,限制为前500个字符
698
 
699
  参数:
700
  url (str): 要抓取文本的网址
701
 
702
  返回:
703
- str: 抓取到的文本,最多为前500个字符
704
  """
705
  headers = {
706
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36',
@@ -716,9 +739,25 @@ def scrape_text(url, proxies) -> str:
716
  for script in soup(["script", "style"]):
717
  script.extract()
718
  text = soup.get_text()
 
719
  # 截取文本,限制最多500个字符
720
  text = text[:500]
721
- return text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
722
 
723
  # 定义函数:联网搜索并更新聊天界面
724
  def GGSearch(
@@ -763,8 +802,8 @@ def GGSearch(
763
  # 更新聊天界面和历史记录
764
  chatbot.append(("联网搜索结果:", GGSearchins))
765
  history.append(("联网搜索结果:", GGSearchins))
766
-
767
- user_input = txtSumins+GGSearchins
768
 
769
  # 继续正常的 GPT 对话流程
770
  yield from predict(
@@ -778,7 +817,7 @@ def GGSearch(
778
  past_key_values=None,
779
  )
780
 
781
-
782
 
783
 
784
  with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) as demo:
@@ -786,7 +825,7 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
786
  gr.HTML(
787
  """<center><a href="https://huggingface.co/spaces/mikeee/chatglm2-6b-4bit?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>It's beyond Fitness,模型由[帛凡]基于ChatGLM-6B进行微调后,在健康(全科)、心理等领域达至少60分的专业水准,而且中文总结能力超越了GPT3.5各版本。</center>"""
788
  """<center>特别声明:本应用仅为模型能力演示,无任何商业行为,部署资源为Huggingface官方免费提供,任何通过此项目产生的知识仅用于学术参考,作者和网站均不承担任何责任。</center>"""
789
- """<h1 align="center">🐰帛凡 Fitness AI🐰 演示</h1>"""
790
  """<center><a href="https://huggingface.co/fb700/chatglm-fitness-RLHF">Bofan基于chatglm-6B的微调模型</a>如果喜欢请给个 💖 。遇到任何问题可邮件和我联系👉 fb700@qq.com</center>"""
791
  )
792
 
@@ -842,11 +881,12 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
842
  txtSumBtn = gr.Button("文字总结", variant="primary")
843
  teachPlanBtn = gr.Button("教案编写", variant="secondary")
844
  allSecretaryBtn = gr.Button("全能文秘", variant="secondary")
845
- redBookBtn = gr.Button("📕小红书帖子", variant="secondary")
 
846
  with gr.Row():
847
  fitnessAskBtn = gr.Button("🥼健康咨询", variant="primary")
848
  mindAskBtn = gr.Button("😶‍🌫️心理咨询", variant="primary")
849
- GGSearchBtn = gr.Button("🐞联网搜索", variant="primary")
850
 
851
  with gr.Column(scale=1):
852
  gr.HTML("""<h3 align="center">🍀您好,除健康咨询和心理��询外,其它功能使用前,请先清空历史,并输入问题。🍀</h3>""")
@@ -1178,7 +1218,7 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
1178
  # outputs = [chatbot, history, last_user_message, user_message]
1179
  outputs=[chatbot, history, past_key_values],
1180
  )
1181
-
1182
  GGSearchBtn.click(
1183
  reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
1184
  )
@@ -1195,7 +1235,8 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
1195
  ],
1196
  # outputs = [chatbot, history, last_user_message, user_message]
1197
  outputs=[chatbot, history, past_key_values],
1198
- )
 
1199
  deleteBtn.click(delete_last_turn, [chatbot, history], [chatbot, history])
1200
 
1201
  with gr.Accordion("Example inputs", open=False):
@@ -1303,4 +1344,4 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
1303
  # reduce to 5 if OOM occurs to often
1304
 
1305
  #demo.queue(concurrency_count=6, max_size=30).launch(debug=True)
1306
- demo.queue(concurrency_count=3, max_size=10).launch(debug=True, auth=eval(os.environ.get("AUTHENTICATION")))
 
23
  RETRY_FLAG = False
24
 
25
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
26
+ #model = AutoModel.from_pretrained(model_name, trust_remote_code=True).quantize(8).half().cuda()
27
+ model = AutoModel.from_pretrained(model_name, trust_remote_code=True).half().cuda()
28
  model = model.eval()
29
 
30
  _ = """Override Chatbot.postprocess"""
 
331
  flowchartins = """
332
  "instruction": "现在你是一个分析师,你需要按照要求将我给你的内容或者主题以Mermaid语言生成足够深度以包含尽量多主要细节的流程图。学习下面的<context></context>里面的知识来完成分析。如果通过<context></context>的学习找不到答案,只需说你不知道。请不要编造答案。",
333
  "input":
334
+ "<context>
335
+ 用户问题: 购买奶茶
336
  答案:
337
  graph TD;
338
  A[客户进入奶茶店] --> B[浏览店内菜单并选择奶茶口味和大小];
 
346
  I --> |有问题| E;
347
  I --> |没问题| K[将奶茶交给客户并感谢客户光临];
348
  K --> L[客户拿着奶茶离开奶茶店享受美味的饮品];
349
+ 请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  用户问题:根据所给内容:"当用户要找一张图片,告诉用户打开浏览器从收藏夹中找到bofanAI,打开网页后滚动到聊天窗口下方,在示例区点双击样例第一项后,样例提示词将出现在输入窗,在输入窗中用其它英文语单词替换monkey,然后点击发送后将接收到5张照片的小图,鼠标右键点击小图获取大图,在跳出的菜单中选择在新标签页打开,就可以在新标签页获取大图。接下来,你可以检查图片是否有误, 如果有问题则鼠标右键点击小图获取大图,如果没问题可以将图片保持在本地。"
351
  答案:
352
  graph TD;
 
363
  K --> L[检查图片是否有误];
364
  L --> |有问题| I[鼠标右键点击小图获取大图];
365
  L --> |没问题| M[将图片保持在本地];
366
+ 请复制生成内容至https://mermaid-js.github.io/mermaid-live-editor/。"
367
  </context>
368
  用户问题:
369
  """
 
556
  history,
557
  past_key_values,
558
  )
559
+ '''
560
  redBookins = """
561
  1、如果用户没有输入,请你告诉他:请输入你想写的内容
562
  2、收到用户输入,按照下面是小红书帖子进行编写:
 
587
  用户输入:
588
 
589
  """
590
+ '''
591
+ redBookins="请你用最华丽、最真诚和最有感情的语言祝:顺欣妈妈、昊昊爸爸、昊昊生日快乐!请大量的使用🎂、❤️、💖、🥳、🥂、🎈、🎊、🎉、🎁、🍾等表示庆祝的的Emoji"
592
  def redBook(
593
  user_input, chatbot, max_length, top_p, temperature, history, past_key_values
594
  ):
595
 
596
+ user_input = redBookins
597
+ #user_input = redBookins+user_input
598
 
599
  yield from predict(
600
  RETRY_FLAG, # type: ignore
 
675
  past_key_values,
676
  )
677
 
678
+ # 导入所需模块
679
+
680
+ from bs4 import BeautifulSoup
681
+ import requests
682
+
683
+ '''
684
+ # 定义函数:从网页中抓取文本
685
+ def scrape_text(url, proxies) -> str:
686
+ """从网页抓取文本
687
+
688
+ 参数:
689
+ url (str): 要抓取文本的网址
690
+
691
+ 返回:
692
+ str: 抓取到的文本
693
+ """
694
+ headers = {
695
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36',
696
+ 'Content-Type': 'text/plain',
697
+ }
698
+ try:
699
+ response = requests.get(url, headers=headers, proxies=proxies, timeout=8)
700
+ if response.encoding == "ISO-8859-1":
701
+ response.encoding = response.apparent_encoding
702
+ except:
703
+ return "无法连接到该网页"
704
+ soup = BeautifulSoup(response.text, "html.parser")
705
+ for script in soup(["script", "style"]):
706
+ script.extract()
707
+ text = soup.get_text()
708
+ lines = (line.strip() for line in text.splitlines())
709
+ chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
710
+ text = "\n".join(chunk for chunk in chunks if chunk)
711
+ return text
712
+ '''
713
+ # 修改函数:从网页中抓取文本,限制为前500个字符
714
+ # 导入所需模块
715
  from bs4 import BeautifulSoup
716
  import requests
717
 
718
+ # 定义函数:从网页中抓取文本并根据长度和回车/空格前字符数进行筛选
719
  def scrape_text(url, proxies) -> str:
720
+ """从网页抓取文本,限制为前500个字符,丢弃字符数小于10的行和连续的空格键、回车键之间字符数小于10的部分
721
 
722
  参数:
723
  url (str): 要抓取文本的网址
724
 
725
  返回:
726
+ str: 抓取到的文本,最多为前500个字符,丢弃字符数小于10的行和连续的空格键、回车键之间字符数小于10的部分
727
  """
728
  headers = {
729
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36',
 
739
  for script in soup(["script", "style"]):
740
  script.extract()
741
  text = soup.get_text()
742
+
743
  # 截取文本,限制最多500个字符
744
  text = text[:500]
745
+
746
+ # 丢弃字符数小于10的行和连续的空格键、回车键之间字符数小于10的部分
747
+ lines = text.split('\n')
748
+ selected_lines = []
749
+ for line in lines:
750
+ # 去除多余的空格
751
+ cleaned_line = ' '.join(line.split())
752
+ if len(cleaned_line) >= 27:
753
+ selected_lines.append(cleaned_line)
754
+
755
+ # 拼接选中的行
756
+ selected_text = '\n'.join(selected_lines)
757
+
758
+ return selected_text
759
+
760
+
761
 
762
  # 定义函数:联网搜索并更新聊天界面
763
  def GGSearch(
 
802
  # 更新聊天界面和历史记录
803
  chatbot.append(("联网搜索结果:", GGSearchins))
804
  history.append(("联网搜索结果:", GGSearchins))
805
+ ggins1="请围用户搜索主题,对搜索结果进行全面的总结。\n用户搜索主题:"
806
+ user_input =ggins1+ user_input+ "\n搜索结果:\n"+ GGSearchins
807
 
808
  # 继续正常的 GPT 对话流程
809
  yield from predict(
 
817
  past_key_values=None,
818
  )
819
 
820
+
821
 
822
 
823
  with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) as demo:
 
825
  gr.HTML(
826
  """<center><a href="https://huggingface.co/spaces/mikeee/chatglm2-6b-4bit?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>It's beyond Fitness,模型由[帛凡]基于ChatGLM-6B进行微调后,在健康(全科)、心理等领域达至少60分的专业水准,而且中文总结能力超越了GPT3.5各版本。</center>"""
827
  """<center>特别声明:本应用仅为模型能力演示,无任何商业行为,部署资源为Huggingface官方免费提供,任何通过此项目产生的知识仅用于学术参考,作者和网站均不承担任何责任。</center>"""
828
+ """<h1 align="center">🐰帛凡 Fitness AI🐰 演示🥂🎈祝顺欣妈妈、昊昊爸爸、昊昊生日快乐!🎂❤️</h1>"""
829
  """<center><a href="https://huggingface.co/fb700/chatglm-fitness-RLHF">Bofan基于chatglm-6B的微调模型</a>如果喜欢请给个 💖 。遇到任何问题可邮件和我联系👉 fb700@qq.com</center>"""
830
  )
831
 
 
881
  txtSumBtn = gr.Button("文字总结", variant="primary")
882
  teachPlanBtn = gr.Button("教案编写", variant="secondary")
883
  allSecretaryBtn = gr.Button("全能文秘", variant="secondary")
884
+ #redBookBtn = gr.Button("📕小红书帖子", variant="secondary")
885
+ redBookBtn = gr.Button("🎂生日快乐🎂", variant="secondary")
886
  with gr.Row():
887
  fitnessAskBtn = gr.Button("🥼健康咨询", variant="primary")
888
  mindAskBtn = gr.Button("😶‍🌫️心理咨询", variant="primary")
889
+ GGSearchBtn = gr.Button("联网搜索", variant="primary")
890
 
891
  with gr.Column(scale=1):
892
  gr.HTML("""<h3 align="center">🍀您好,除健康咨询和心理��询外,其它功能使用前,请先清空历史,并输入问题。🍀</h3>""")
 
1218
  # outputs = [chatbot, history, last_user_message, user_message]
1219
  outputs=[chatbot, history, past_key_values],
1220
  )
1221
+ # 绑定函数到联网搜索按钮的点击事件
1222
  GGSearchBtn.click(
1223
  reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
1224
  )
 
1235
  ],
1236
  # outputs = [chatbot, history, last_user_message, user_message]
1237
  outputs=[chatbot, history, past_key_values],
1238
+ )
1239
+
1240
  deleteBtn.click(delete_last_turn, [chatbot, history], [chatbot, history])
1241
 
1242
  with gr.Accordion("Example inputs", open=False):
 
1344
  # reduce to 5 if OOM occurs to often
1345
 
1346
  #demo.queue(concurrency_count=6, max_size=30).launch(debug=True)
1347
+ demo.queue(concurrency_count=6, max_size=30).launch(debug=True, auth=eval(os.environ.get("AUTHENTICATION")))