Spaces:
Runtime error
Runtime error
Update ChuanhuChatbot.py
Browse files- ChuanhuChatbot.py +97 -97
ChuanhuChatbot.py
CHANGED
@@ -39,7 +39,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
39 |
user_api_key = gr.State(my_api_key)
|
40 |
current_model = gr.State()
|
41 |
|
42 |
-
topic = gr.State(i18n("
|
43 |
|
44 |
with gr.Row(elem_id="chuanhu-header"):
|
45 |
gr.HTML(get_html("header_title.html").format(
|
@@ -53,7 +53,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
53 |
version_time=version_time(),
|
54 |
cancel_btn=i18n("取消"),
|
55 |
update_btn=i18n("更新"),
|
56 |
-
seenew_btn=i18n("
|
57 |
ok_btn=i18n("好"),
|
58 |
), visible=check_update)
|
59 |
|
@@ -66,7 +66,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
66 |
with gr.Row(elem_id="chuanhu-history-search-row"):
|
67 |
with gr.Column(min_width=150, scale=2):
|
68 |
historySearchTextbox = gr.Textbox(show_label=False, container=False, placeholder=i18n(
|
69 |
-
"
|
70 |
with gr.Column(min_width=52, scale=1, elem_id="gr-history-header-btns"):
|
71 |
uploadFileBtn = gr.UploadButton(
|
72 |
interactive=True, label="", file_types=[".json"], elem_id="gr-history-upload-btn")
|
@@ -76,7 +76,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
76 |
with gr.Row(elem_id="chuanhu-history-body"):
|
77 |
with gr.Column(scale=6, elem_id="history-select-wrap"):
|
78 |
historySelectList = gr.Radio(
|
79 |
-
label=i18n("
|
80 |
choices=get_history_names(),
|
81 |
value=get_first_history_name(),
|
82 |
# multiselect=False,
|
@@ -97,17 +97,17 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
97 |
with gr.Column(scale=6):
|
98 |
saveFileName = gr.Textbox(
|
99 |
show_label=True,
|
100 |
-
placeholder=i18n("
|
101 |
-
label=i18n("
|
102 |
-
value=i18n("
|
103 |
elem_classes="no-container"
|
104 |
# container=False,
|
105 |
)
|
106 |
with gr.Column(scale=1):
|
107 |
renameHistoryBtn = gr.Button(
|
108 |
-
i18n("💾
|
109 |
exportMarkdownBtn = gr.Button(
|
110 |
-
i18n("📝
|
111 |
|
112 |
with gr.Column(elem_id="chuanhu-menu-footer", visible=True): #, visible=False
|
113 |
with gr.Row(elem_id="chuanhu-func-nav"):
|
@@ -119,16 +119,16 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
119 |
with gr.Column(elem_id="chatbot-area"):
|
120 |
with gr.Row(elem_id="chatbot-header"):
|
121 |
model_select_dropdown = gr.Dropdown(
|
122 |
-
label=i18n("
|
123 |
show_label=False, container=False, elem_id="model-select-dropdown"
|
124 |
)
|
125 |
lora_select_dropdown = gr.Dropdown(
|
126 |
-
label=i18n("
|
127 |
container=False,
|
128 |
)
|
129 |
gr.HTML(get_html("chatbot_header_btn.html").format(
|
130 |
-
json_label=i18n("
|
131 |
-
md_label=i18n("
|
132 |
), elem_id="chatbot-header-btn-bar")
|
133 |
with gr.Row():
|
134 |
chatbot = gr.Chatbot(
|
@@ -144,18 +144,18 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
144 |
with gr.Box(elem_id="chatbot-input-box"):
|
145 |
with gr.Row(elem_id="chatbot-input-row"):
|
146 |
gr.HTML(get_html("chatbot_more.html").format(
|
147 |
-
single_turn_label=i18n("
|
148 |
-
websearch_label=i18n("
|
149 |
-
upload_file_label=i18n("
|
150 |
-
uploaded_files_label=i18n("
|
151 |
-
uploaded_files_tip=i18n("
|
152 |
))
|
153 |
with gr.Row(elem_id="chatbot-input-tb-row"):
|
154 |
with gr.Column(min_width=225, scale=12):
|
155 |
user_input = gr.Textbox(
|
156 |
elem_id="user-input-tb",
|
157 |
show_label=False,
|
158 |
-
placeholder=i18n("
|
159 |
elem_classes="no-container",
|
160 |
max_lines=5,
|
161 |
# container=False
|
@@ -169,16 +169,16 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
169 |
with gr.Row(elem_id="chatbot-buttons", visible=False):
|
170 |
with gr.Column(min_width=120, scale=1):
|
171 |
emptyBtn = gr.Button(
|
172 |
-
i18n("🧹
|
173 |
)
|
174 |
with gr.Column(min_width=120, scale=1):
|
175 |
retryBtn = gr.Button(
|
176 |
i18n("🔄 重新生成"), elem_id="gr-retry-btn")
|
177 |
with gr.Column(min_width=120, scale=1):
|
178 |
-
delFirstBtn = gr.Button(i18n("🗑️
|
179 |
with gr.Column(min_width=120, scale=1):
|
180 |
delLastBtn = gr.Button(
|
181 |
-
i18n("🗑️
|
182 |
with gr.Row(visible=False) as like_dislike_area:
|
183 |
with gr.Column(min_width=20, scale=1):
|
184 |
likeBtn = gr.Button(
|
@@ -196,21 +196,21 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
196 |
obj="toolbox"), elem_classes="close-btn")
|
197 |
|
198 |
|
199 |
-
with gr.Accordion(label=i18n("
|
200 |
use_websearch_checkbox = gr.Checkbox(label=i18n(
|
201 |
-
"
|
202 |
index_files = gr.Files(label=i18n(
|
203 |
-
"
|
204 |
two_column = gr.Checkbox(label=i18n(
|
205 |
-
"
|
206 |
-
summarize_btn = gr.Button(i18n("
|
207 |
# TODO: 公式ocr
|
208 |
-
# formula_ocr = gr.Checkbox(label=i18n("
|
209 |
|
210 |
|
211 |
|
212 |
with gr.Tabs(elem_id="chuanhu-toolbox-tabs",visible=False) as tabs:
|
213 |
-
with gr.Tab(label=i18n("
|
214 |
keyTxt = gr.Textbox(
|
215 |
show_label=True,
|
216 |
placeholder=f"Your API-key...",
|
@@ -222,19 +222,19 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
222 |
with gr.Accordion(label="Prompt", open=True , visible=False): #, visible=False
|
223 |
systemPromptTxt = gr.Textbox(
|
224 |
show_label=True,
|
225 |
-
placeholder=i18n("
|
226 |
label="System prompt",
|
227 |
value=INITIAL_SYSTEM_PROMPT,
|
228 |
lines=8
|
229 |
)
|
230 |
retain_system_prompt_checkbox = gr.Checkbox(
|
231 |
-
label=i18n("
|
232 |
-
with gr.Accordion(label=i18n("
|
233 |
with gr.Column():
|
234 |
with gr.Row():
|
235 |
with gr.Column(scale=6):
|
236 |
templateFileSelectDropdown = gr.Dropdown(
|
237 |
-
label=i18n("
|
238 |
choices=get_template_names(),
|
239 |
multiselect=False,
|
240 |
value=get_template_names()[0],
|
@@ -246,7 +246,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
246 |
with gr.Row():
|
247 |
with gr.Column():
|
248 |
templateSelectDropdown = gr.Dropdown(
|
249 |
-
label=i18n("
|
250 |
choices=load_template(
|
251 |
get_template_names()[
|
252 |
0], mode=1
|
@@ -255,21 +255,21 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
255 |
container=False,
|
256 |
)
|
257 |
gr.Markdown("---", elem_classes="hr-line")
|
258 |
-
with gr.Accordion(label=i18n("
|
259 |
use_websearch_checkbox = gr.Checkbox(label=i18n(
|
260 |
-
"
|
261 |
index_files = gr.Files(label=i18n(
|
262 |
-
"
|
263 |
two_column = gr.Checkbox(label=i18n(
|
264 |
-
"
|
265 |
-
summarize_btn = gr.Button(i18n("
|
266 |
# TODO: 公式ocr
|
267 |
-
# formula_ocr = gr.Checkbox(label=i18n("
|
268 |
|
269 |
-
with gr.Tab(label=i18n("
|
270 |
-
gr.Markdown(i18n("# ⚠️
|
271 |
elem_id="advanced-warning")
|
272 |
-
with gr.Accordion(i18n("
|
273 |
temperature_slider = gr.Slider(
|
274 |
minimum=-0,
|
275 |
maximum=2.0,
|
@@ -296,7 +296,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
296 |
)
|
297 |
stop_sequence_txt = gr.Textbox(
|
298 |
show_label=True,
|
299 |
-
placeholder=i18n("
|
300 |
label="stop",
|
301 |
value="",
|
302 |
lines=1,
|
@@ -341,8 +341,8 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
341 |
)
|
342 |
user_identifier_txt = gr.Textbox(
|
343 |
show_label=True,
|
344 |
-
placeholder=i18n("
|
345 |
-
label=i18n("
|
346 |
value=user_name.value,
|
347 |
lines=1,
|
348 |
)
|
@@ -350,73 +350,73 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
350 |
gr.Markdown(
|
351 |
"Will be here soon...\n(We hope)\n\nAnd we hope you can help us to make more extensions!")
|
352 |
|
353 |
-
# changeAPIURLBtn = gr.Button(i18n("🔄
|
354 |
|
355 |
with gr.Row(elem_id="popup-wrapper"):
|
356 |
with gr.Box(elem_id="chuanhu-popup"):
|
357 |
with gr.Box(elem_id="chuanhu-setting"):
|
358 |
with gr.Row():
|
359 |
-
gr.Markdown("## "+i18n("
|
360 |
gr.HTML(get_html("close_btn.html").format(
|
361 |
obj="box"), elem_classes="close-btn")
|
362 |
with gr.Tabs(elem_id="chuanhu-setting-tabs"):
|
363 |
with gr.Tab(label=i18n("模型")):
|
364 |
if multi_api_key:
|
365 |
usageTxt = gr.Markdown(i18n(
|
366 |
-
"
|
367 |
else:
|
368 |
usageTxt = gr.Markdown(i18n(
|
369 |
-
"
|
370 |
# model_select_dropdown = gr.Dropdown(
|
371 |
-
# label=i18n("
|
372 |
# )
|
373 |
# lora_select_dropdown = gr.Dropdown(
|
374 |
-
# label=i18n("
|
375 |
# )
|
376 |
# with gr.Row():
|
377 |
|
378 |
language_select_dropdown = gr.Dropdown(
|
379 |
-
label=i18n("
|
380 |
choices=REPLY_LANGUAGES,
|
381 |
multiselect=False,
|
382 |
value=REPLY_LANGUAGES[0],
|
383 |
)
|
384 |
|
385 |
-
with gr.Tab(label=i18n("
|
386 |
gr.HTML(get_html("appearance_switcher.html").format(
|
387 |
-
label=i18n("
|
388 |
use_streaming_checkbox = gr.Checkbox(
|
389 |
-
label=i18n("
|
390 |
)
|
391 |
name_chat_method = gr.Dropdown(
|
392 |
-
label=i18n("
|
393 |
choices=HISTORY_NAME_METHODS,
|
394 |
multiselect=False,
|
395 |
interactive=True,
|
396 |
value=HISTORY_NAME_METHODS[chat_name_method_index],
|
397 |
)
|
398 |
single_turn_checkbox = gr.Checkbox(label=i18n(
|
399 |
-
"
|
400 |
-
# checkUpdateBtn = gr.Button(i18n("🔄
|
401 |
|
402 |
-
with gr.Tab(i18n("
|
403 |
gr.Markdown(
|
404 |
-
i18n("⚠️
|
405 |
-
default_btn = gr.Button(i18n("🔙
|
406 |
-
#
|
407 |
proxyTxt = gr.Textbox(
|
408 |
show_label=True,
|
409 |
-
placeholder=i18n("
|
410 |
-
label=i18n("
|
411 |
value=config.http_proxy,
|
412 |
lines=1,
|
413 |
interactive=False,
|
414 |
# container=False,
|
415 |
elem_classes="view-only-textbox no-container",
|
416 |
)
|
417 |
-
# changeProxyBtn = gr.Button(i18n("🔄
|
418 |
|
419 |
-
#
|
420 |
apihostTxt = gr.Textbox(
|
421 |
show_label=True,
|
422 |
placeholder="api.openai.com",
|
@@ -428,7 +428,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
428 |
elem_classes="view-only-textbox no-container",
|
429 |
)
|
430 |
|
431 |
-
with gr.Tab(label=i18n("
|
432 |
gr.Markdown(
|
433 |
'<img alt="Chuanhu Chat logo" src="file=web_assets/icon/any-icon-512.png" style="max-width: 144px;">')
|
434 |
gr.Markdown("# "+i18n("川虎Chat"))
|
@@ -438,55 +438,55 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
438 |
|
439 |
with gr.Box(elem_id="chuanhu-training"):
|
440 |
with gr.Row():
|
441 |
-
gr.Markdown("## "+i18n("
|
442 |
gr.HTML(get_html("close_btn.html").format(
|
443 |
obj="box"), elem_classes="close-btn")
|
444 |
with gr.Tabs(elem_id="chuanhu-training-tabs"):
|
445 |
-
with gr.Tab(label="OpenAI "+i18n("
|
446 |
-
openai_train_status = gr.Markdown(label=i18n("
|
447 |
-
"查看[
|
448 |
|
449 |
-
with gr.Tab(label=i18n("
|
450 |
dataset_preview_json = gr.JSON(
|
451 |
-
label=i18n("
|
452 |
-
dataset_selection = gr.Files(label=i18n("
|
453 |
".xlsx", ".jsonl"], file_count="single")
|
454 |
upload_to_openai_btn = gr.Button(
|
455 |
-
i18n("
|
456 |
|
457 |
-
with gr.Tab(label=i18n("
|
458 |
openai_ft_file_id = gr.Textbox(label=i18n(
|
459 |
-
"
|
460 |
openai_ft_suffix = gr.Textbox(label=i18n(
|
461 |
-
"
|
462 |
openai_train_epoch_slider = gr.Slider(label=i18n(
|
463 |
-
"
|
464 |
openai_start_train_btn = gr.Button(
|
465 |
-
i18n("
|
466 |
|
467 |
-
with gr.Tab(label=i18n("
|
468 |
-
openai_status_refresh_btn = gr.Button(i18n("
|
469 |
openai_cancel_all_jobs_btn = gr.Button(
|
470 |
-
i18n("
|
471 |
add_to_models_btn = gr.Button(
|
472 |
-
i18n("
|
473 |
|
474 |
with gr.Box(elem_id="web-config", visible=False):
|
475 |
gr.HTML(get_html('web_config.html').format(
|
476 |
enableCheckUpdate_config=check_update,
|
477 |
hideHistoryWhenNotLoggedIn_config=hide_history_when_not_logged_in,
|
478 |
-
forView_i18n=i18n("
|
479 |
-
deleteConfirm_i18n_pref=i18n("
|
480 |
-
deleteConfirm_i18n_suff=i18n("
|
481 |
usingLatest_i18n=i18n("您使用的就是最新版!"),
|
482 |
-
updatingMsg_i18n=i18n("
|
483 |
-
updateSuccess_i18n=i18n("
|
484 |
updateFailure_i18n=i18n(
|
485 |
-
"
|
486 |
regenerate_i18n=i18n("重新生成"),
|
487 |
-
deleteRound_i18n=i18n("
|
488 |
-
renameChat_i18n=i18n("
|
489 |
-
validFileName_i18n=i18n("
|
490 |
))
|
491 |
with gr.Box(elem_id="fake-gradio-components", visible=False):
|
492 |
updateChuanhuBtn = gr.Button(
|
@@ -802,10 +802,10 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
802 |
|
803 |
logging.info(
|
804 |
colorama.Back.GREEN
|
805 |
-
+ "\n
|
806 |
+ colorama.Style.RESET_ALL
|
807 |
)
|
808 |
-
#
|
809 |
demo.title = i18n("川虎Chat 🚀")
|
810 |
|
811 |
if __name__ == "__main__":
|
@@ -814,5 +814,5 @@ if __name__ == "__main__":
|
|
814 |
allowed_paths=["history", "web_assets"],
|
815 |
auth=auth_from_conf if authflag else None,
|
816 |
favicon_path="./web_assets/favicon.ico",
|
817 |
-
inbrowser=not dockerflag, # 禁止在docker
|
818 |
)
|
|
|
39 |
user_api_key = gr.State(my_api_key)
|
40 |
current_model = gr.State()
|
41 |
|
42 |
+
topic = gr.State(i18n("未命名對話歷史記錄"))
|
43 |
|
44 |
with gr.Row(elem_id="chuanhu-header"):
|
45 |
gr.HTML(get_html("header_title.html").format(
|
|
|
53 |
version_time=version_time(),
|
54 |
cancel_btn=i18n("取消"),
|
55 |
update_btn=i18n("更新"),
|
56 |
+
seenew_btn=i18n("詳情"),
|
57 |
ok_btn=i18n("好"),
|
58 |
), visible=check_update)
|
59 |
|
|
|
66 |
with gr.Row(elem_id="chuanhu-history-search-row"):
|
67 |
with gr.Column(min_width=150, scale=2):
|
68 |
historySearchTextbox = gr.Textbox(show_label=False, container=False, placeholder=i18n(
|
69 |
+
"搜索(支援正則)..."), lines=1, elem_id="history-search-tb")
|
70 |
with gr.Column(min_width=52, scale=1, elem_id="gr-history-header-btns"):
|
71 |
uploadFileBtn = gr.UploadButton(
|
72 |
interactive=True, label="", file_types=[".json"], elem_id="gr-history-upload-btn")
|
|
|
76 |
with gr.Row(elem_id="chuanhu-history-body"):
|
77 |
with gr.Column(scale=6, elem_id="history-select-wrap"):
|
78 |
historySelectList = gr.Radio(
|
79 |
+
label=i18n("從清單中載入對話"),
|
80 |
choices=get_history_names(),
|
81 |
value=get_first_history_name(),
|
82 |
# multiselect=False,
|
|
|
97 |
with gr.Column(scale=6):
|
98 |
saveFileName = gr.Textbox(
|
99 |
show_label=True,
|
100 |
+
placeholder=i18n("設置檔案名: 默認為.json,可選為.md"),
|
101 |
+
label=i18n("設置保存檔案名"),
|
102 |
+
value=i18n("對話歷史記錄"),
|
103 |
elem_classes="no-container"
|
104 |
# container=False,
|
105 |
)
|
106 |
with gr.Column(scale=1):
|
107 |
renameHistoryBtn = gr.Button(
|
108 |
+
i18n("💾 保存對話"), elem_id="gr-history-save-btn")
|
109 |
exportMarkdownBtn = gr.Button(
|
110 |
+
i18n("📝 匯出為 Markdown"), elem_id="gr-markdown-export-btn")
|
111 |
|
112 |
with gr.Column(elem_id="chuanhu-menu-footer", visible=True): #, visible=False
|
113 |
with gr.Row(elem_id="chuanhu-func-nav"):
|
|
|
119 |
with gr.Column(elem_id="chatbot-area"):
|
120 |
with gr.Row(elem_id="chatbot-header"):
|
121 |
model_select_dropdown = gr.Dropdown(
|
122 |
+
label=i18n("選擇模型"), choices=MODELS, multiselect=False, value=MODELS[DEFAULT_MODEL], interactive=True,
|
123 |
show_label=False, container=False, elem_id="model-select-dropdown"
|
124 |
)
|
125 |
lora_select_dropdown = gr.Dropdown(
|
126 |
+
label=i18n("選擇LoRA模型"), choices=[], multiselect=False, interactive=True, visible=False,
|
127 |
container=False,
|
128 |
)
|
129 |
gr.HTML(get_html("chatbot_header_btn.html").format(
|
130 |
+
json_label=i18n("歷史記錄(JSON)"),
|
131 |
+
md_label=i18n("匯出為 Markdown")
|
132 |
), elem_id="chatbot-header-btn-bar")
|
133 |
with gr.Row():
|
134 |
chatbot = gr.Chatbot(
|
|
|
144 |
with gr.Box(elem_id="chatbot-input-box"):
|
145 |
with gr.Row(elem_id="chatbot-input-row"):
|
146 |
gr.HTML(get_html("chatbot_more.html").format(
|
147 |
+
single_turn_label=i18n("單輪對話"),
|
148 |
+
websearch_label=i18n("線上搜索"),
|
149 |
+
upload_file_label=i18n("上傳文件"),
|
150 |
+
uploaded_files_label=i18n("知識庫文件"),
|
151 |
+
uploaded_files_tip=i18n("在工具箱中管理知識庫文件")
|
152 |
))
|
153 |
with gr.Row(elem_id="chatbot-input-tb-row"):
|
154 |
with gr.Column(min_width=225, scale=12):
|
155 |
user_input = gr.Textbox(
|
156 |
elem_id="user-input-tb",
|
157 |
show_label=False,
|
158 |
+
placeholder=i18n("在這裡輸入"),
|
159 |
elem_classes="no-container",
|
160 |
max_lines=5,
|
161 |
# container=False
|
|
|
169 |
with gr.Row(elem_id="chatbot-buttons", visible=False):
|
170 |
with gr.Column(min_width=120, scale=1):
|
171 |
emptyBtn = gr.Button(
|
172 |
+
i18n("🧹 新的對話"), elem_id="empty-btn"
|
173 |
)
|
174 |
with gr.Column(min_width=120, scale=1):
|
175 |
retryBtn = gr.Button(
|
176 |
i18n("🔄 重新生成"), elem_id="gr-retry-btn")
|
177 |
with gr.Column(min_width=120, scale=1):
|
178 |
+
delFirstBtn = gr.Button(i18n("🗑️ 刪除最舊對話"))
|
179 |
with gr.Column(min_width=120, scale=1):
|
180 |
delLastBtn = gr.Button(
|
181 |
+
i18n("🗑️ 刪除最新對話"), elem_id="gr-dellast-btn")
|
182 |
with gr.Row(visible=False) as like_dislike_area:
|
183 |
with gr.Column(min_width=20, scale=1):
|
184 |
likeBtn = gr.Button(
|
|
|
196 |
obj="toolbox"), elem_classes="close-btn")
|
197 |
|
198 |
|
199 |
+
with gr.Accordion(label=i18n("知識庫"), open=True):
|
200 |
use_websearch_checkbox = gr.Checkbox(label=i18n(
|
201 |
+
"使用線上搜索"), value=False, elem_classes="switch-checkbox", elem_id="gr-websearch-cb", visible=False)
|
202 |
index_files = gr.Files(label=i18n(
|
203 |
+
"上傳"), type="file", elem_id="upload-index-file")
|
204 |
two_column = gr.Checkbox(label=i18n(
|
205 |
+
"雙欄pdf"), value=advance_docs["pdf"].get("two_column", False))
|
206 |
+
summarize_btn = gr.Button(i18n("總結"))
|
207 |
# TODO: 公式ocr
|
208 |
+
# formula_ocr = gr.Checkbox(label=i18n("識別公式"), value=advance_docs["pdf"].get("formula_ocr", False))
|
209 |
|
210 |
|
211 |
|
212 |
with gr.Tabs(elem_id="chuanhu-toolbox-tabs",visible=False) as tabs:
|
213 |
+
with gr.Tab(label=i18n("對話")):
|
214 |
keyTxt = gr.Textbox(
|
215 |
show_label=True,
|
216 |
placeholder=f"Your API-key...",
|
|
|
222 |
with gr.Accordion(label="Prompt", open=True , visible=False): #, visible=False
|
223 |
systemPromptTxt = gr.Textbox(
|
224 |
show_label=True,
|
225 |
+
placeholder=i18n("在這裡輸入System Prompt..."),
|
226 |
label="System prompt",
|
227 |
value=INITIAL_SYSTEM_PROMPT,
|
228 |
lines=8
|
229 |
)
|
230 |
retain_system_prompt_checkbox = gr.Checkbox(
|
231 |
+
label=i18n("新建對話保留Prompt"), value=False, visible=True, elem_classes="switch-checkbox")
|
232 |
+
with gr.Accordion(label=i18n("載入Prompt範本"), open=False):
|
233 |
with gr.Column():
|
234 |
with gr.Row():
|
235 |
with gr.Column(scale=6):
|
236 |
templateFileSelectDropdown = gr.Dropdown(
|
237 |
+
label=i18n("選擇Prompt範本集合檔"),
|
238 |
choices=get_template_names(),
|
239 |
multiselect=False,
|
240 |
value=get_template_names()[0],
|
|
|
246 |
with gr.Row():
|
247 |
with gr.Column():
|
248 |
templateSelectDropdown = gr.Dropdown(
|
249 |
+
label=i18n("從Prompt範本中載入"),
|
250 |
choices=load_template(
|
251 |
get_template_names()[
|
252 |
0], mode=1
|
|
|
255 |
container=False,
|
256 |
)
|
257 |
gr.Markdown("---", elem_classes="hr-line")
|
258 |
+
with gr.Accordion(label=i18n("知識庫"), open=True):
|
259 |
use_websearch_checkbox = gr.Checkbox(label=i18n(
|
260 |
+
"使用線上搜索"), value=False, elem_classes="switch-checkbox", elem_id="gr-websearch-cb", visible=False)
|
261 |
index_files = gr.Files(label=i18n(
|
262 |
+
"上傳"), type="file", elem_id="upload-index-file")
|
263 |
two_column = gr.Checkbox(label=i18n(
|
264 |
+
"雙欄pdf"), value=advance_docs["pdf"].get("two_column", False))
|
265 |
+
summarize_btn = gr.Button(i18n("總結"))
|
266 |
# TODO: 公式ocr
|
267 |
+
# formula_ocr = gr.Checkbox(label=i18n("識別公式"), value=advance_docs["pdf"].get("formula_ocr", False))
|
268 |
|
269 |
+
with gr.Tab(label=i18n("參數")):
|
270 |
+
gr.Markdown(i18n("# ⚠️ 務必謹慎更改 ⚠️"),
|
271 |
elem_id="advanced-warning")
|
272 |
+
with gr.Accordion(i18n("參數"), open=True):
|
273 |
temperature_slider = gr.Slider(
|
274 |
minimum=-0,
|
275 |
maximum=2.0,
|
|
|
296 |
)
|
297 |
stop_sequence_txt = gr.Textbox(
|
298 |
show_label=True,
|
299 |
+
placeholder=i18n("停止符,用英文逗號隔開..."),
|
300 |
label="stop",
|
301 |
value="",
|
302 |
lines=1,
|
|
|
341 |
)
|
342 |
user_identifier_txt = gr.Textbox(
|
343 |
show_label=True,
|
344 |
+
placeholder=i18n("用於定位濫用行為"),
|
345 |
+
label=i18n("用戶名"),
|
346 |
value=user_name.value,
|
347 |
lines=1,
|
348 |
)
|
|
|
350 |
gr.Markdown(
|
351 |
"Will be here soon...\n(We hope)\n\nAnd we hope you can help us to make more extensions!")
|
352 |
|
353 |
+
# changeAPIURLBtn = gr.Button(i18n("🔄 切換API位址"))
|
354 |
|
355 |
with gr.Row(elem_id="popup-wrapper"):
|
356 |
with gr.Box(elem_id="chuanhu-popup"):
|
357 |
with gr.Box(elem_id="chuanhu-setting"):
|
358 |
with gr.Row():
|
359 |
+
gr.Markdown("## "+i18n("設置"))
|
360 |
gr.HTML(get_html("close_btn.html").format(
|
361 |
obj="box"), elem_classes="close-btn")
|
362 |
with gr.Tabs(elem_id="chuanhu-setting-tabs"):
|
363 |
with gr.Tab(label=i18n("模型")):
|
364 |
if multi_api_key:
|
365 |
usageTxt = gr.Markdown(i18n(
|
366 |
+
"多帳號模式已開啟,無需輸入key,可直接開始對話"), elem_id="usage-display", elem_classes="insert-block", visible=show_api_billing)
|
367 |
else:
|
368 |
usageTxt = gr.Markdown(i18n(
|
369 |
+
"**發送消息** 或 **提交key** 以顯示額度"), elem_id="usage-display", elem_classes="insert-block", visible=show_api_billing)
|
370 |
# model_select_dropdown = gr.Dropdown(
|
371 |
+
# label=i18n("選擇模型"), choices=MODELS, multiselect=False, value=MODELS[DEFAULT_MODEL], interactive=True
|
372 |
# )
|
373 |
# lora_select_dropdown = gr.Dropdown(
|
374 |
+
# label=i18n("選擇LoRA模型"), choices=[], multiselect=False, interactive=True, visible=False
|
375 |
# )
|
376 |
# with gr.Row():
|
377 |
|
378 |
language_select_dropdown = gr.Dropdown(
|
379 |
+
label=i18n("選擇回復語言(針對搜索&索引功能)"),
|
380 |
choices=REPLY_LANGUAGES,
|
381 |
multiselect=False,
|
382 |
value=REPLY_LANGUAGES[0],
|
383 |
)
|
384 |
|
385 |
+
with gr.Tab(label=i18n("高級")):
|
386 |
gr.HTML(get_html("appearance_switcher.html").format(
|
387 |
+
label=i18n("切換亮暗色主題")), elem_classes="insert-block", visible=False)
|
388 |
use_streaming_checkbox = gr.Checkbox(
|
389 |
+
label=i18n("即時傳輸回答"), value=True, visible=ENABLE_STREAMING_OPTION, elem_classes="switch-checkbox"
|
390 |
)
|
391 |
name_chat_method = gr.Dropdown(
|
392 |
+
label=i18n("對話命名方式"),
|
393 |
choices=HISTORY_NAME_METHODS,
|
394 |
multiselect=False,
|
395 |
interactive=True,
|
396 |
value=HISTORY_NAME_METHODS[chat_name_method_index],
|
397 |
)
|
398 |
single_turn_checkbox = gr.Checkbox(label=i18n(
|
399 |
+
"單輪對話"), value=False, elem_classes="switch-checkbox", elem_id="gr-single-session-cb", visible=False)
|
400 |
+
# checkUpdateBtn = gr.Button(i18n("🔄 檢查更新..."), visible=check_update)
|
401 |
|
402 |
+
with gr.Tab(i18n("網路")):
|
403 |
gr.Markdown(
|
404 |
+
i18n("⚠️ 為保證API-Key安全,請在設定檔`config.json`中修改網路設置"), elem_id="netsetting-warning")
|
405 |
+
default_btn = gr.Button(i18n("🔙 恢復預設網路設置"))
|
406 |
+
# 網路代理
|
407 |
proxyTxt = gr.Textbox(
|
408 |
show_label=True,
|
409 |
+
placeholder=i18n("未設置代理..."),
|
410 |
+
label=i18n("代理位址"),
|
411 |
value=config.http_proxy,
|
412 |
lines=1,
|
413 |
interactive=False,
|
414 |
# container=False,
|
415 |
elem_classes="view-only-textbox no-container",
|
416 |
)
|
417 |
+
# changeProxyBtn = gr.Button(i18n("🔄 設置代理位址"))
|
418 |
|
419 |
+
# 優先展示自訂的api_host
|
420 |
apihostTxt = gr.Textbox(
|
421 |
show_label=True,
|
422 |
placeholder="api.openai.com",
|
|
|
428 |
elem_classes="view-only-textbox no-container",
|
429 |
)
|
430 |
|
431 |
+
with gr.Tab(label=i18n("關於"), elem_id="about-tab"):
|
432 |
gr.Markdown(
|
433 |
'<img alt="Chuanhu Chat logo" src="file=web_assets/icon/any-icon-512.png" style="max-width: 144px;">')
|
434 |
gr.Markdown("# "+i18n("川虎Chat"))
|
|
|
438 |
|
439 |
with gr.Box(elem_id="chuanhu-training"):
|
440 |
with gr.Row():
|
441 |
+
gr.Markdown("## "+i18n("訓練"))
|
442 |
gr.HTML(get_html("close_btn.html").format(
|
443 |
obj="box"), elem_classes="close-btn")
|
444 |
with gr.Tabs(elem_id="chuanhu-training-tabs"):
|
445 |
+
with gr.Tab(label="OpenAI "+i18n("微調")):
|
446 |
+
openai_train_status = gr.Markdown(label=i18n("訓練狀態"), value=i18n(
|
447 |
+
"查看[使用介紹](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用教程#微調-gpt-35)"))
|
448 |
|
449 |
+
with gr.Tab(label=i18n("準備資料集")):
|
450 |
dataset_preview_json = gr.JSON(
|
451 |
+
label=i18n("資料集預覽"))
|
452 |
+
dataset_selection = gr.Files(label=i18n("選擇資料集"), file_types=[
|
453 |
".xlsx", ".jsonl"], file_count="single")
|
454 |
upload_to_openai_btn = gr.Button(
|
455 |
+
i18n("上傳到OpenAI"), variant="primary", interactive=False)
|
456 |
|
457 |
+
with gr.Tab(label=i18n("訓練")):
|
458 |
openai_ft_file_id = gr.Textbox(label=i18n(
|
459 |
+
"檔ID"), value="", lines=1, placeholder=i18n("上傳到 OpenAI 後自動填充"))
|
460 |
openai_ft_suffix = gr.Textbox(label=i18n(
|
461 |
+
"模型名稱尾碼"), value="", lines=1, placeholder=i18n("可選,用於區分不同的模型"))
|
462 |
openai_train_epoch_slider = gr.Slider(label=i18n(
|
463 |
+
"訓練輪數(Epochs)"), minimum=1, maximum=100, value=3, step=1, interactive=True)
|
464 |
openai_start_train_btn = gr.Button(
|
465 |
+
i18n("開始訓練"), variant="primary", interactive=False)
|
466 |
|
467 |
+
with gr.Tab(label=i18n("狀態")):
|
468 |
+
openai_status_refresh_btn = gr.Button(i18n("刷新狀態"))
|
469 |
openai_cancel_all_jobs_btn = gr.Button(
|
470 |
+
i18n("取消所有任務"))
|
471 |
add_to_models_btn = gr.Button(
|
472 |
+
i18n("添加訓練好的模型到模型清單"), interactive=False)
|
473 |
|
474 |
with gr.Box(elem_id="web-config", visible=False):
|
475 |
gr.HTML(get_html('web_config.html').format(
|
476 |
enableCheckUpdate_config=check_update,
|
477 |
hideHistoryWhenNotLoggedIn_config=hide_history_when_not_logged_in,
|
478 |
+
forView_i18n=i18n("僅供查看"),
|
479 |
+
deleteConfirm_i18n_pref=i18n("你真的要刪除 "),
|
480 |
+
deleteConfirm_i18n_suff=i18n(" 嗎?"),
|
481 |
usingLatest_i18n=i18n("您使用的就是最新版!"),
|
482 |
+
updatingMsg_i18n=i18n("正在嘗試更新..."),
|
483 |
+
updateSuccess_i18n=i18n("更新成功,請重啟本程式"),
|
484 |
updateFailure_i18n=i18n(
|
485 |
+
"更新失敗,請嘗試[手動更新](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用教程#手動更新)"),
|
486 |
regenerate_i18n=i18n("重新生成"),
|
487 |
+
deleteRound_i18n=i18n("刪除這輪問答"),
|
488 |
+
renameChat_i18n=i18n("重命名該對話"),
|
489 |
+
validFileName_i18n=i18n("請輸入有效的檔案名,不要包含以下特殊字元:"),
|
490 |
))
|
491 |
with gr.Box(elem_id="fake-gradio-components", visible=False):
|
492 |
updateChuanhuBtn = gr.Button(
|
|
|
802 |
|
803 |
logging.info(
|
804 |
colorama.Back.GREEN
|
805 |
+
+ "\n川虎的溫馨提示:訪問 http://localhost:7860 查看介面"
|
806 |
+ colorama.Style.RESET_ALL
|
807 |
)
|
808 |
+
# 默認開啟本機伺服器,默認可以直接從IP訪問,預設不創建公開分享連結
|
809 |
demo.title = i18n("川虎Chat 🚀")
|
810 |
|
811 |
if __name__ == "__main__":
|
|
|
814 |
allowed_paths=["history", "web_assets"],
|
815 |
auth=auth_from_conf if authflag else None,
|
816 |
favicon_path="./web_assets/favicon.ico",
|
817 |
+
inbrowser=not dockerflag, # 禁止在docker下開啟inbrowser
|
818 |
)
|