Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -101,6 +101,10 @@ def repeat_to_one_fb(x):
|
|
101 |
|
102 |
repeat_to_one = repeat_to_one_fb
|
103 |
|
|
|
|
|
|
|
|
|
104 |
from huggingface_hub import snapshot_download
|
105 |
|
106 |
if not os.path.exists("genshin-impact-character"):
|
@@ -746,7 +750,11 @@ def get_single_prompt(
|
|
746 |
character_setting_rewrite_dict = character_setting_rewrite_dict,
|
747 |
Text = Text,
|
748 |
)
|
749 |
-
|
|
|
|
|
|
|
|
|
750 |
|
751 |
def get_two_prompt(
|
752 |
single_name_1, select_gender_1, select_country_1, single_identity_1, single_disposition_1,
|
@@ -828,7 +836,11 @@ def get_two_prompt(
|
|
828 |
character_setting_rewrite_dict_1 = character_setting_rewrite_dict_1,
|
829 |
character_setting_rewrite_dict_2 = character_setting_rewrite_dict_2,
|
830 |
)
|
831 |
-
|
|
|
|
|
|
|
|
|
832 |
|
833 |
import re
|
834 |
import pandas as pd
|
@@ -865,8 +877,8 @@ model_file_path = "genshin_impact_character_llamazh13b_ggml/llama2zh-13b-3900-q4
|
|
865 |
from llama_cpp import Llama
|
866 |
llama = Llama(model_file_path,
|
867 |
n_ctx = 4090,
|
868 |
-
n_threads=
|
869 |
-
|
870 |
)
|
871 |
print("load {}".format(model_file_path))
|
872 |
|
@@ -996,6 +1008,7 @@ def run_single(
|
|
996 |
|
997 |
req = "\n\n".join(map(lambda t2: "结果{}:\n{}".format(t2[0], t2[1]), enumerate(req)))
|
998 |
req = process_text(req)
|
|
|
999 |
return req
|
1000 |
|
1001 |
def run_two(
|
@@ -1030,6 +1043,7 @@ def run_two(
|
|
1030 |
req = req_
|
1031 |
req = "\n\n".join(map(lambda t2: "结果{}:\n{}".format(t2[0], t2[1]), enumerate(req)))
|
1032 |
req = process_text(req)
|
|
|
1033 |
return req
|
1034 |
|
1035 |
all_single_task = ["介绍", "故事", "信", "聊天", "时候", "关于", "了解"]
|
@@ -1084,73 +1098,9 @@ with gr.Blocks() as demo:
|
|
1084 |
with gr.Row():
|
1085 |
single_prompt_run_button = gr.Button("得到任务结果")
|
1086 |
output = gr.Text(label = "任务生成结果", info = "可编辑", lines = 2, scale = 5.0)
|
1087 |
-
|
1088 |
-
with gr.Tab("两个角色看法指令"):
|
1089 |
-
with gr.Row():
|
1090 |
-
with gr.Column(0.5):
|
1091 |
-
with gr.Column():
|
1092 |
-
select_name_1 = gr.Gallery(im_list, elem_id="gallery",
|
1093 |
-
#scale = 0.1,
|
1094 |
-
columns=[5], object_fit="contain",
|
1095 |
-
#height=2048 + 1024,
|
1096 |
-
height=512+128,
|
1097 |
-
allow_preview = False,
|
1098 |
-
label="选择角色",
|
1099 |
-
info = "可选择。原神沉玉谷前的内建角色"
|
1100 |
-
)
|
1101 |
-
single_name_1 = gr.Text(label = "角色姓名",
|
1102 |
-
info = "可编辑。角色姓名会重写选择角色,用这个选项可以新建角色",
|
1103 |
-
interactive = True)
|
1104 |
-
with gr.Row():
|
1105 |
-
select_gender_1 = gr.Dropdown(label="性别",
|
1106 |
-
choices=all_genders,
|
1107 |
-
info = "可选择",
|
1108 |
-
value=all_genders[0], interactive = True)
|
1109 |
-
select_country_1 = gr.Dropdown(label="国籍",
|
1110 |
-
choices=all_countries,
|
1111 |
-
info = "可选择",
|
1112 |
-
value=all_countries[0], interactive = True)
|
1113 |
-
#with gr.Column():
|
1114 |
-
single_identity_1 = gr.Text(label = "身份", info = "可编辑", interactive = True)
|
1115 |
-
single_disposition_1 = gr.Text(label = "性格特征", info = "可编辑", interactive = True)
|
1116 |
-
single_introduction_1 = gr.Text(label = "角色介绍", info = "可编辑",
|
1117 |
-
interactive = True, lines = 36)
|
1118 |
-
|
1119 |
-
with gr.Column(0.5):
|
1120 |
-
with gr.Column():
|
1121 |
-
select_name_2 = gr.Gallery(im_list, elem_id="gallery",
|
1122 |
-
#scale = 0.1,
|
1123 |
-
columns=[5], object_fit="contain",
|
1124 |
-
#height=2048 + 1024,
|
1125 |
-
height=512+128,
|
1126 |
-
allow_preview = False,
|
1127 |
-
label="选择角色",
|
1128 |
-
info = "可选择。原神沉玉谷前的内建角色"
|
1129 |
-
)
|
1130 |
-
single_name_2 = gr.Text(label = "角色姓名",
|
1131 |
-
info = "可编辑。角色姓名会重写选择角色,用这个选项可以新建角色",
|
1132 |
-
interactive = True)
|
1133 |
-
with gr.Row():
|
1134 |
-
select_gender_2 = gr.Dropdown(label="性别",
|
1135 |
-
choices=all_genders,
|
1136 |
-
info = "可选择",
|
1137 |
-
value=all_genders[0], interactive = True)
|
1138 |
-
select_country_2 = gr.Dropdown(label="国籍",
|
1139 |
-
choices=all_countries,
|
1140 |
-
info = "可选择",
|
1141 |
-
value=all_countries[0], interactive = True)
|
1142 |
-
#with gr.Column():
|
1143 |
-
single_identity_2 = gr.Text(label = "身份", info = "可编辑", interactive = True)
|
1144 |
-
single_disposition_2 = gr.Text(label = "性格特征", info = "可编辑", interactive = True)
|
1145 |
-
single_introduction_2 = gr.Text(label = "角色介绍", info = "可编辑",
|
1146 |
-
interactive = True, lines = 36)
|
1147 |
-
|
1148 |
-
with gr.Row():
|
1149 |
-
two_prompt_run_button = gr.Button("得到角色间看法")
|
1150 |
-
two_output = gr.Text(label = "角色间看法结果", info = "可编辑", lines = 2, scale = 5.0)
|
1151 |
-
|
1152 |
with gr.Row():
|
1153 |
-
gen_times = gr.Slider(1, 10, value=
|
1154 |
max_length = gr.Slider(0, 32768, value=512, step=1.0, label="Maximum length", interactive=True)
|
1155 |
top_p = gr.Slider(0, 1, value=0.8, step=0.01, label="Top P", interactive=True)
|
1156 |
temperature = gr.Slider(0.01, 1, value=0.6, step=0.01, label="Temperature", interactive=True)
|
@@ -1173,11 +1123,11 @@ with gr.Blocks() as demo:
|
|
1173 |
with gr.Row():
|
1174 |
gr.Examples(
|
1175 |
[
|
1176 |
-
["这里推荐从左面选择:行秋" ,"故事", "一天行秋到望舒客栈吃饭。"],
|
1177 |
["这里推荐从左面选择:柯莱" ,"信", "鸟语花香"],
|
1178 |
["这里推荐从左面选择:夜兰" ,"聊天", "夜来香"],
|
1179 |
["这里推荐从左面选择:凝光" ,"时候", "品尝璃月香茗"],
|
1180 |
["这里推荐从左面选择:可莉" ,"关于", "如何制造蹦蹦炸弹"],
|
|
|
1181 |
["这里推荐从左面选择:北斗" ,"了解", ""],
|
1182 |
],
|
1183 |
inputs = [single_name ,select_task, Text],
|
@@ -1209,43 +1159,7 @@ with gr.Blocks() as demo:
|
|
1209 |
],
|
1210 |
label = "单个角色任务指令例子"
|
1211 |
)
|
1212 |
-
|
1213 |
-
with gr.Row():
|
1214 |
-
gr.Examples(
|
1215 |
-
[
|
1216 |
-
["这里推荐从上面选择:芙宁娜", "这里推荐从上面选择:那维莱特"]
|
1217 |
-
],
|
1218 |
-
inputs = [single_name_1, single_name_2],
|
1219 |
-
label = "两个角色看法指令例子"
|
1220 |
-
)
|
1221 |
-
|
1222 |
-
with gr.Row():
|
1223 |
-
gr.Examples(
|
1224 |
-
[
|
1225 |
-
["这里推荐从上面选择:提纳里" ,"大慈树王",
|
1226 |
-
"成年女性", "须弥", "须弥的统治者",
|
1227 |
-
"爱民如子,带领雨林的人民战胜灾厄",
|
1228 |
-
'''
|
1229 |
-
草神之所以也被称之为“智慧之神”,正是因为她的意识连接着世界之树。在须弥人眼里,她是智慧的化身、仁慈与无所不能的象征,但她却在几百年前的灾难中消失了。
|
1230 |
-
在漫长的历史当中,须弥历经浩劫,种种险情都被大慈树王一一化解。大慈树王创造出雨林,使得须弥人能获得安宁的生活。而须弥最初的教令院,便是由长久地去追随大慈树王的学者组成,他们各司其职,协助大慈树王管理须弥。最能理解大慈树王的力量和哲思的,只能是教令院了。
|
1231 |
-
'''
|
1232 |
-
],
|
1233 |
-
],
|
1234 |
-
inputs = [single_name_1 ,single_name_2,
|
1235 |
-
select_gender_2, select_country_2, single_identity_2,
|
1236 |
-
single_disposition_2, single_introduction_2
|
1237 |
-
],
|
1238 |
-
label = "两个角色看法指令例子"
|
1239 |
-
)
|
1240 |
-
|
1241 |
-
select_name_1.select(
|
1242 |
-
get_single_name, select_name_1, single_name_1
|
1243 |
-
)
|
1244 |
-
|
1245 |
-
select_name_2.select(
|
1246 |
-
get_single_name, select_name_2, single_name_2
|
1247 |
-
)
|
1248 |
-
|
1249 |
select_name.select(change_single_name,
|
1250 |
inputs = select_name,
|
1251 |
outputs = [
|
@@ -1254,31 +1168,12 @@ with gr.Blocks() as demo:
|
|
1254 |
],
|
1255 |
)
|
1256 |
|
1257 |
-
select_name_1.select(
|
1258 |
-
change_single_name, select_name_1,
|
1259 |
-
[single_name_1, select_gender_1, select_country_1,
|
1260 |
-
single_identity_1, single_disposition_1, single_introduction_1
|
1261 |
-
]
|
1262 |
-
)
|
1263 |
-
|
1264 |
-
select_name_2.select(
|
1265 |
-
change_single_name, select_name_2,
|
1266 |
-
[single_name_2, select_gender_2, select_country_2,
|
1267 |
-
single_identity_2, single_disposition_2, single_introduction_2
|
1268 |
-
]
|
1269 |
-
)
|
1270 |
-
|
1271 |
single_prompt_run_button.click(run_single, [
|
1272 |
single_name, select_gender, select_country, single_identity, single_disposition,
|
1273 |
select_task, Text, single_introduction,
|
1274 |
gen_times, max_length, top_p, temperature
|
1275 |
], output)
|
1276 |
-
|
1277 |
-
single_name_1, select_gender_1, select_country_1, single_identity_1, single_disposition_1,
|
1278 |
-
single_introduction_1,
|
1279 |
-
single_name_2, select_gender_2, select_country_2, single_identity_2, single_disposition_2,
|
1280 |
-
single_introduction_2,
|
1281 |
-
gen_times, max_length, top_p, temperature], two_output)
|
1282 |
|
1283 |
#demo.launch("0.0.0.0", show_api=False, share = True)
|
1284 |
demo.queue(max_size=4, concurrency_count=1).launch(debug=True, show_api=False, share = True)
|
|
|
101 |
|
102 |
repeat_to_one = repeat_to_one_fb
|
103 |
|
104 |
+
def process_info(x, maintain_chars = ",.。,;::;??\n——"):
|
105 |
+
req = re.findall(u"[0-9\u4e00-\u9fa5{}]+".format(maintain_chars) ,x)
|
106 |
+
return "".join(req)
|
107 |
+
|
108 |
from huggingface_hub import snapshot_download
|
109 |
|
110 |
if not os.path.exists("genshin-impact-character"):
|
|
|
750 |
character_setting_rewrite_dict = character_setting_rewrite_dict,
|
751 |
Text = Text,
|
752 |
)
|
753 |
+
#a = a.replace("?", "?")
|
754 |
+
req = "\n".join([b, a])
|
755 |
+
req = process_info(req)
|
756 |
+
return req
|
757 |
+
#return "\n".join([b, a])
|
758 |
|
759 |
def get_two_prompt(
|
760 |
single_name_1, select_gender_1, select_country_1, single_identity_1, single_disposition_1,
|
|
|
836 |
character_setting_rewrite_dict_1 = character_setting_rewrite_dict_1,
|
837 |
character_setting_rewrite_dict_2 = character_setting_rewrite_dict_2,
|
838 |
)
|
839 |
+
#a = a.replace("?", "?")
|
840 |
+
req = "\n".join([b, a])
|
841 |
+
req = process_info(req)
|
842 |
+
return req
|
843 |
+
#return "\n".join([b, a])
|
844 |
|
845 |
import re
|
846 |
import pandas as pd
|
|
|
877 |
from llama_cpp import Llama
|
878 |
llama = Llama(model_file_path,
|
879 |
n_ctx = 4090,
|
880 |
+
n_threads=8, # The number of CPU threads to use, tailor to your system and the resulting performance
|
881 |
+
n_gpu_layers=-1
|
882 |
)
|
883 |
print("load {}".format(model_file_path))
|
884 |
|
|
|
1008 |
|
1009 |
req = "\n\n".join(map(lambda t2: "结果{}:\n{}".format(t2[0], t2[1]), enumerate(req)))
|
1010 |
req = process_text(req)
|
1011 |
+
#req = process_info(req)
|
1012 |
return req
|
1013 |
|
1014 |
def run_two(
|
|
|
1043 |
req = req_
|
1044 |
req = "\n\n".join(map(lambda t2: "结果{}:\n{}".format(t2[0], t2[1]), enumerate(req)))
|
1045 |
req = process_text(req)
|
1046 |
+
#req = process_info(req)
|
1047 |
return req
|
1048 |
|
1049 |
all_single_task = ["介绍", "故事", "信", "聊天", "时候", "关于", "了解"]
|
|
|
1098 |
with gr.Row():
|
1099 |
single_prompt_run_button = gr.Button("得到任务结果")
|
1100 |
output = gr.Text(label = "任务生成结果", info = "可编辑", lines = 2, scale = 5.0)
|
1101 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1102 |
with gr.Row():
|
1103 |
+
gen_times = gr.Slider(1, 10, value=10, step=1.0, label="Generate Num", interactive=True)
|
1104 |
max_length = gr.Slider(0, 32768, value=512, step=1.0, label="Maximum length", interactive=True)
|
1105 |
top_p = gr.Slider(0, 1, value=0.8, step=0.01, label="Top P", interactive=True)
|
1106 |
temperature = gr.Slider(0.01, 1, value=0.6, step=0.01, label="Temperature", interactive=True)
|
|
|
1123 |
with gr.Row():
|
1124 |
gr.Examples(
|
1125 |
[
|
|
|
1126 |
["这里推荐从左面选择:柯莱" ,"信", "鸟语花香"],
|
1127 |
["这里推荐从左面选择:夜兰" ,"聊天", "夜来香"],
|
1128 |
["这里推荐从左面选择:凝光" ,"时候", "品尝璃月香茗"],
|
1129 |
["这里推荐从左面选择:可莉" ,"关于", "如何制造蹦蹦炸弹"],
|
1130 |
+
["这里推荐从左面选择:行秋" ,"故事", "一天行秋到望舒客栈吃饭。"],
|
1131 |
["这里推荐从左面选择:北斗" ,"了解", ""],
|
1132 |
],
|
1133 |
inputs = [single_name ,select_task, Text],
|
|
|
1159 |
],
|
1160 |
label = "单个角色任务指令例子"
|
1161 |
)
|
1162 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1163 |
select_name.select(change_single_name,
|
1164 |
inputs = select_name,
|
1165 |
outputs = [
|
|
|
1168 |
],
|
1169 |
)
|
1170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1171 |
single_prompt_run_button.click(run_single, [
|
1172 |
single_name, select_gender, select_country, single_identity, single_disposition,
|
1173 |
select_task, Text, single_introduction,
|
1174 |
gen_times, max_length, top_p, temperature
|
1175 |
], output)
|
1176 |
+
|
|
|
|
|
|
|
|
|
|
|
1177 |
|
1178 |
#demo.launch("0.0.0.0", show_api=False, share = True)
|
1179 |
demo.queue(max_size=4, concurrency_count=1).launch(debug=True, show_api=False, share = True)
|