Spaces:
Runtime error
Runtime error
Update 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 |
|
@@ -27,8 +27,6 @@ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
27 |
model = AutoModel.from_pretrained(model_name, trust_remote_code=True).half().cuda()
|
28 |
model = model.eval()
|
29 |
|
30 |
-
|
31 |
-
|
32 |
_ = """Override Chatbot.postprocess"""
|
33 |
|
34 |
|
@@ -575,7 +573,7 @@ def allSecretary(
|
|
575 |
history,
|
576 |
past_key_values,
|
577 |
)
|
578 |
-
'''
|
579 |
redBookins = """
|
580 |
1、如果用户没有输入,请你告诉他:请输入你想写的内容
|
581 |
2、收到用户输入,按照下面是小红书帖子进行编写:
|
@@ -606,13 +604,12 @@ redBookins = """
|
|
606 |
用户输入:
|
607 |
|
608 |
"""
|
609 |
-
'''
|
610 |
-
redBookins="
|
611 |
def redBook(
|
612 |
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
613 |
):
|
614 |
|
615 |
-
|
616 |
user_input = redBookins
|
617 |
#user_input = redBookins+user_input
|
618 |
|
@@ -694,17 +691,56 @@ def mindAsk(
|
|
694 |
history,
|
695 |
past_key_values,
|
696 |
)
|
697 |
-
|
698 |
-
|
|
|
699 |
from bs4 import BeautifulSoup
|
700 |
import requests
|
701 |
|
|
|
|
|
|
|
|
|
702 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
703 |
|
704 |
|
705 |
# 定义函数:从网页中抓取文本并根据长度和回车/空格前字符数进行筛选
|
706 |
def scrape_text(url, proxies) -> str:
|
|
|
707 |
|
|
|
|
|
|
|
|
|
|
|
|
|
708 |
headers = {
|
709 |
'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',
|
710 |
'Content-Type': 'text/plain',
|
@@ -787,7 +823,7 @@ def GGSearch(
|
|
787 |
history.append(("联网搜索结果:", GGSearchins))
|
788 |
|
789 |
#user_input =ggins1+ user_input+ "\n搜索结果:\n"+ GGSearchins
|
790 |
-
user_input =
|
791 |
|
792 |
# 继续正常的 GPT 对话流程
|
793 |
yield from predict(
|
@@ -801,7 +837,7 @@ def GGSearch(
|
|
801 |
past_key_values=None,
|
802 |
)
|
803 |
|
804 |
-
|
805 |
|
806 |
|
807 |
with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) as demo:
|
@@ -1202,7 +1238,7 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
1202 |
# outputs = [chatbot, history, last_user_message, user_message]
|
1203 |
outputs=[chatbot, history, past_key_values],
|
1204 |
)
|
1205 |
-
# 绑定函数到联网搜索按钮的点击事件
|
1206 |
GGSearchBtn.click(
|
1207 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
1208 |
)
|
@@ -1328,4 +1364,4 @@ with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) a
|
|
1328 |
# reduce to 5 if OOM occurs to often
|
1329 |
|
1330 |
#demo.queue(concurrency_count=6, max_size=30).launch(debug=True)
|
1331 |
-
demo.queue(concurrency_count=
|
|
|
18 |
|
19 |
|
20 |
|
21 |
+
model_name = "fb700/chatglm-fitness-RLHF"
|
22 |
|
23 |
RETRY_FLAG = False
|
24 |
|
|
|
27 |
model = AutoModel.from_pretrained(model_name, trust_remote_code=True).half().cuda()
|
28 |
model = model.eval()
|
29 |
|
|
|
|
|
30 |
_ = """Override Chatbot.postprocess"""
|
31 |
|
32 |
|
|
|
573 |
history,
|
574 |
past_key_values,
|
575 |
)
|
576 |
+
'''
|
577 |
redBookins = """
|
578 |
1、如果用户没有输入,请你告诉他:请输入你想写的内容
|
579 |
2、收到用户输入,按照下面是小红书帖子进行编写:
|
|
|
604 |
用户输入:
|
605 |
|
606 |
"""
|
607 |
+
'''
|
608 |
+
redBookins="请你用最华丽、最真诚和最有感情的语言祝:顺欣妈妈、昊昊爸爸、昊昊生日快乐!请大量的使用🎂、❤️、💖、🥳、🥂、🎈、🎊、🎉、🎁、🍾等表示庆祝的的Emoji"
|
609 |
def redBook(
|
610 |
user_input, chatbot, max_length, top_p, temperature, history, past_key_values
|
611 |
):
|
612 |
|
|
|
613 |
user_input = redBookins
|
614 |
#user_input = redBookins+user_input
|
615 |
|
|
|
691 |
history,
|
692 |
past_key_values,
|
693 |
)
|
694 |
+
|
695 |
+
# 导入所需模块
|
696 |
+
|
697 |
from bs4 import BeautifulSoup
|
698 |
import requests
|
699 |
|
700 |
+
'''
|
701 |
+
# 定义函数:从网页中抓取文本
|
702 |
+
def scrape_text(url, proxies) -> str:
|
703 |
+
"""从网页抓取文本
|
704 |
|
705 |
+
参数:
|
706 |
+
url (str): 要抓取文本的网址
|
707 |
+
|
708 |
+
返回:
|
709 |
+
str: 抓取到的文本
|
710 |
+
"""
|
711 |
+
headers = {
|
712 |
+
'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',
|
713 |
+
'Content-Type': 'text/plain',
|
714 |
+
}
|
715 |
+
try:
|
716 |
+
response = requests.get(url, headers=headers, proxies=proxies, timeout=8)
|
717 |
+
if response.encoding == "ISO-8859-1":
|
718 |
+
response.encoding = response.apparent_encoding
|
719 |
+
except:
|
720 |
+
return "无法连接到该网页"
|
721 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
722 |
+
for script in soup(["script", "style"]):
|
723 |
+
script.extract()
|
724 |
+
text = soup.get_text()
|
725 |
+
lines = (line.strip() for line in text.splitlines())
|
726 |
+
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
727 |
+
text = "\n".join(chunk for chunk in chunks if chunk)
|
728 |
+
return text
|
729 |
+
'''
|
730 |
+
# 修改函数:从网页中抓取文本,限制为前500个字符
|
731 |
+
# 导入所需模块
|
732 |
|
733 |
|
734 |
# 定义函数:从网页中抓取文本并根据长度和回车/空格前字符数进行筛选
|
735 |
def scrape_text(url, proxies) -> str:
|
736 |
+
"""从网页抓取文本,限制为前500个字符,丢弃字符数小于10的行和连续的空格键、回车键之间字符数小于10的部分
|
737 |
|
738 |
+
参数:
|
739 |
+
url (str): 要抓取文本的网址
|
740 |
+
|
741 |
+
返回:
|
742 |
+
str: 抓取到的文本,最多为前500个字符,丢弃字符数小于10的行和连续的空格键、回车键之间字符数小于10的部分
|
743 |
+
"""
|
744 |
headers = {
|
745 |
'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',
|
746 |
'Content-Type': 'text/plain',
|
|
|
823 |
history.append(("联网搜索结果:", GGSearchins))
|
824 |
|
825 |
#user_input =ggins1+ user_input+ "\n搜索结果:\n"+ GGSearchins
|
826 |
+
user_input ="将以下文字概括为 200 个字,使其易于阅读和理解。避免使用复杂的句子结构或技术术语。"+ GGSearchins
|
827 |
|
828 |
# 继续正常的 GPT 对话流程
|
829 |
yield from predict(
|
|
|
837 |
past_key_values=None,
|
838 |
)
|
839 |
|
840 |
+
|
841 |
|
842 |
|
843 |
with gr.Blocks(title="🐰Bofan Ai🐰", theme=gr.themes.Soft(text_size="sm")) as demo:
|
|
|
1238 |
# outputs = [chatbot, history, last_user_message, user_message]
|
1239 |
outputs=[chatbot, history, past_key_values],
|
1240 |
)
|
1241 |
+
# 绑定函数到联网搜索按钮的点击事件
|
1242 |
GGSearchBtn.click(
|
1243 |
reset_state, outputs=[chatbot, history, past_key_values], show_progress="full"
|
1244 |
)
|
|
|
1364 |
# reduce to 5 if OOM occurs to often
|
1365 |
|
1366 |
#demo.queue(concurrency_count=6, max_size=30).launch(debug=True)
|
1367 |
+
demo.queue(concurrency_count=6, max_size=30).launch(debug=True, auth=eval(os.environ.get("AUTHENTICATION")))
|