simondby commited on
Commit ·
eb8a298
1
Parent(s): 47c25c9
update auth
Browse files- .gitignore +2 -1
- app.py +13 -12
- modules/chat_func.py +1 -1
- modules/utils.py +2 -0
.gitignore
CHANGED
|
@@ -140,4 +140,5 @@ auth.json
|
|
| 140 |
|
| 141 |
deprecated/
|
| 142 |
.vscode
|
| 143 |
-
thunder-tests
|
|
|
|
|
|
| 140 |
|
| 141 |
deprecated/
|
| 142 |
.vscode
|
| 143 |
+
thunder-tests
|
| 144 |
+
*.ipynb
|
app.py
CHANGED
|
@@ -72,9 +72,10 @@ PromptHelper.compact_text_chunks = compact_text_chunks
|
|
| 72 |
with open("assets/custom.css", "r", encoding="utf-8") as f:
|
| 73 |
customCSS = f.read()
|
| 74 |
|
| 75 |
-
with gr.Blocks(css=customCSS, theme=gr.themes.Soft()) as
|
| 76 |
history = gr.State([])
|
| 77 |
token_count = gr.State([])
|
|
|
|
| 78 |
promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
|
| 79 |
user_api_key = gr.State(my_api_key)
|
| 80 |
user_question = gr.State("")
|
|
@@ -436,21 +437,21 @@ logging.info(
|
|
| 436 |
+ colorama.Style.RESET_ALL
|
| 437 |
)
|
| 438 |
# 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
|
| 439 |
-
|
| 440 |
|
| 441 |
if __name__ == "__main__":
|
| 442 |
reload_javascript()
|
| 443 |
# if running in Docker
|
| 444 |
if dockerflag:
|
| 445 |
if authflag:
|
| 446 |
-
|
| 447 |
server_name="0.0.0.0",
|
| 448 |
server_port=7860,
|
| 449 |
auth=auth_list,
|
| 450 |
favicon_path="./assets/rocket.png",
|
| 451 |
)
|
| 452 |
else:
|
| 453 |
-
|
| 454 |
server_name="0.0.0.0",
|
| 455 |
server_port=7860,
|
| 456 |
share=False,
|
|
@@ -459,19 +460,19 @@ if __name__ == "__main__":
|
|
| 459 |
# if not running in Docker
|
| 460 |
else:
|
| 461 |
if authflag:
|
| 462 |
-
|
| 463 |
auth=auth_check,
|
| 464 |
favicon_path="./assets/rocket.png",
|
| 465 |
share=False,
|
| 466 |
inbrowser=False,
|
| 467 |
)
|
| 468 |
else:
|
| 469 |
-
|
| 470 |
-
share=False,
|
| 471 |
auth=auth_check,
|
| 472 |
-
favicon_path="./assets/rocket.png"
|
| 473 |
-
|
|
|
|
| 474 |
) # 改为 share=True 可以创建公开分享链接
|
| 475 |
-
#
|
| 476 |
-
#
|
| 477 |
-
#
|
|
|
|
| 72 |
with open("assets/custom.css", "r", encoding="utf-8") as f:
|
| 73 |
customCSS = f.read()
|
| 74 |
|
| 75 |
+
with gr.Blocks(css=customCSS, theme=gr.themes.Soft()) as app:
|
| 76 |
history = gr.State([])
|
| 77 |
token_count = gr.State([])
|
| 78 |
+
current_user = gr.State("")
|
| 79 |
promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
|
| 80 |
user_api_key = gr.State(my_api_key)
|
| 81 |
user_question = gr.State("")
|
|
|
|
| 437 |
+ colorama.Style.RESET_ALL
|
| 438 |
)
|
| 439 |
# 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
|
| 440 |
+
app.title = "Chatbot 🚀"
|
| 441 |
|
| 442 |
if __name__ == "__main__":
|
| 443 |
reload_javascript()
|
| 444 |
# if running in Docker
|
| 445 |
if dockerflag:
|
| 446 |
if authflag:
|
| 447 |
+
app.queue(concurrency_count=CONCURRENT_COUNT).launch(
|
| 448 |
server_name="0.0.0.0",
|
| 449 |
server_port=7860,
|
| 450 |
auth=auth_list,
|
| 451 |
favicon_path="./assets/rocket.png",
|
| 452 |
)
|
| 453 |
else:
|
| 454 |
+
app.queue(concurrency_count=CONCURRENT_COUNT).launch(
|
| 455 |
server_name="0.0.0.0",
|
| 456 |
server_port=7860,
|
| 457 |
share=False,
|
|
|
|
| 460 |
# if not running in Docker
|
| 461 |
else:
|
| 462 |
if authflag:
|
| 463 |
+
app.queue(concurrency_count=CONCURRENT_COUNT).launch(
|
| 464 |
auth=auth_check,
|
| 465 |
favicon_path="./assets/rocket.png",
|
| 466 |
share=False,
|
| 467 |
inbrowser=False,
|
| 468 |
)
|
| 469 |
else:
|
| 470 |
+
app.queue(concurrency_count=CONCURRENT_COUNT).launch(
|
|
|
|
| 471 |
auth=auth_check,
|
| 472 |
+
favicon_path="./assets/rocket.png",
|
| 473 |
+
share=False,
|
| 474 |
+
inbrowser=False,
|
| 475 |
) # 改为 share=True 可以创建公开分享链接
|
| 476 |
+
# app.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口
|
| 477 |
+
# app.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=7860,auth=("在这里填写用户名", "在这里填写密码")) # 可设置用户名与密码
|
| 478 |
+
# app.queue(concurrency_count=CONCURRENT_COUNT).launch(auth=("在这里填写用户名", "在这里填写密码")) # 适合Nginx反向代理
|
modules/chat_func.py
CHANGED
|
@@ -375,7 +375,7 @@ def predict(
|
|
| 375 |
status_text = f"Token 达到上限,已自动降低Token计数至 {status_text}"
|
| 376 |
yield chatbot, history, status_text, all_token_counts
|
| 377 |
|
| 378 |
-
d_logged_in_user =
|
| 379 |
d_system_prompt = system_prompt.replace("\n","")
|
| 380 |
d_inputs = inputs.replace("\n","")
|
| 381 |
d_gpt = history[-1]['content']
|
|
|
|
| 375 |
status_text = f"Token 达到上限,已自动降低Token计数至 {status_text}"
|
| 376 |
yield chatbot, history, status_text, all_token_counts
|
| 377 |
|
| 378 |
+
d_logged_in_user = gr.current_user.value
|
| 379 |
d_system_prompt = system_prompt.replace("\n","")
|
| 380 |
d_inputs = inputs.replace("\n","")
|
| 381 |
d_gpt = history[-1]['content']
|
modules/utils.py
CHANGED
|
@@ -83,7 +83,9 @@ def auth_check(username, password):
|
|
| 83 |
break
|
| 84 |
if if_pass:
|
| 85 |
logging.info(f"Logged in as {username}")
|
|
|
|
| 86 |
ding_send(f"【成功登录】用户名:{username}")
|
|
|
|
| 87 |
else:
|
| 88 |
logging.info(f"Login attempt failed:[{username},{password}]")
|
| 89 |
ding_send(f"【异常登录】用户名:{username},密码:{password}")
|
|
|
|
| 83 |
break
|
| 84 |
if if_pass:
|
| 85 |
logging.info(f"Logged in as {username}")
|
| 86 |
+
gr.current_user = gr.State(username)
|
| 87 |
ding_send(f"【成功登录】用户名:{username}")
|
| 88 |
+
# print(gr.current_user.value)
|
| 89 |
else:
|
| 90 |
logging.info(f"Login attempt failed:[{username},{password}]")
|
| 91 |
ding_send(f"【异常登录】用户名:{username},密码:{password}")
|