Spaces:
Paused
Paused
Tuchuanhuhuhu
commited on
Commit
•
c7e1b86
1
Parent(s):
954bc36
增加并行处理与权限控制
Browse files
config.py
CHANGED
@@ -6,7 +6,7 @@ API_URL = "https://api.openai.com/v1/chat/completions"
|
|
6 |
USE_PROXY = False
|
7 |
if USE_PROXY:
|
8 |
# 代理网络的地址,打开你的科学上网软件查看代理的协议(socks5/http)、地址(localhost)和端口(11284)
|
9 |
-
proxies = { "http": "socks5h://localhost:11284", "https": "socks5h://localhost:11284", }
|
10 |
print('网络代理状态:运行。')
|
11 |
else:
|
12 |
proxies = None
|
@@ -25,5 +25,11 @@ MAX_RETRY = 2
|
|
25 |
LLM_MODEL = "gpt-3.5-turbo"
|
26 |
|
27 |
# 检查一下是不是忘了改config
|
28 |
-
if API_KEY
|
29 |
-
assert False, "请在config文件中修改API密钥, 添加海外代理之后再运行"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
USE_PROXY = False
|
7 |
if USE_PROXY:
|
8 |
# 代理网络的地址,打开你的科学上网软件查看代理的协议(socks5/http)、地址(localhost)和端口(11284)
|
9 |
+
proxies = { "http": "socks5h://localhost:11284", "https": "socks5h://localhost:11284", }
|
10 |
print('网络代理状态:运行。')
|
11 |
else:
|
12 |
proxies = None
|
|
|
25 |
LLM_MODEL = "gpt-3.5-turbo"
|
26 |
|
27 |
# 检查一下是不是忘了改config
|
28 |
+
if len(API_KEY) != 51:
|
29 |
+
assert False, "请在config文件中修改API密钥, 添加海外代理之后再运行"
|
30 |
+
|
31 |
+
# 设置并行使用的线程数
|
32 |
+
CONCURRENT_COUNT = 100
|
33 |
+
|
34 |
+
# 设置用户名和密码
|
35 |
+
AUTHENTICATION = [] # [("username", "password"), ("username2", "password2"), ...]
|
main.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
2 |
-
import gradio as gr
|
3 |
from predict import predict
|
4 |
from toolbox import format_io, find_free_port
|
5 |
|
6 |
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
7 |
-
try: from config_private import proxies, WEB_PORT, LLM_MODEL
|
8 |
-
except: from config import proxies, WEB_PORT, LLM_MODEL
|
9 |
|
10 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
11 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
|
|
12 |
|
13 |
initial_prompt = "Serve me as a writing and programming assistant."
|
14 |
title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
|
@@ -16,7 +17,7 @@ title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
|
|
16 |
# 问询记录, python 版本建议3.9+(越新越好)
|
17 |
import logging
|
18 |
os.makedirs('gpt_log', exist_ok=True)
|
19 |
-
try:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO, encoding='utf-8')
|
20 |
except:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO)
|
21 |
print('所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log, 请注意自我隐私保护哦!')
|
22 |
|
@@ -78,11 +79,11 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
|
78 |
txt.submit(predict, [txt, top_p, temperature, chatbot, history, systemPromptTxt], [chatbot, history, statusDisplay])
|
79 |
submitBtn.click(predict, [txt, top_p, temperature, chatbot, history, systemPromptTxt], [chatbot, history, statusDisplay], show_progress=True)
|
80 |
for k in functional:
|
81 |
-
functional[k]["Button"].click(predict,
|
82 |
[txt, top_p, temperature, chatbot, history, systemPromptTxt, TRUE, gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
83 |
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
|
84 |
for k in crazy_functional:
|
85 |
-
click_handle = crazy_functional[k]["Button"].click(crazy_functional[k]["Function"],
|
86 |
[txt, top_p, temperature, chatbot, history, systemPromptTxt, gr.State(PORT)], [chatbot, history, statusDisplay]
|
87 |
)
|
88 |
try: click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
|
@@ -90,4 +91,4 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
|
90 |
|
91 |
|
92 |
demo.title = "ChatGPT 学术优化"
|
93 |
-
demo.queue().launch(server_name="0.0.0.0", share=True, server_port=PORT, inbrowser=True)
|
|
|
1 |
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
2 |
+
import gradio as gr
|
3 |
from predict import predict
|
4 |
from toolbox import format_io, find_free_port
|
5 |
|
6 |
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
7 |
+
try: from config_private import proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION
|
8 |
+
except: from config import proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION
|
9 |
|
10 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
11 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
12 |
+
AUTHENTICATION = None if AUTHENTICATION == [] else AUTHENTICATION
|
13 |
|
14 |
initial_prompt = "Serve me as a writing and programming assistant."
|
15 |
title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
|
|
|
17 |
# 问询记录, python 版本建议3.9+(越新越好)
|
18 |
import logging
|
19 |
os.makedirs('gpt_log', exist_ok=True)
|
20 |
+
try:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO, encoding='utf-8')
|
21 |
except:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO)
|
22 |
print('所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log, 请注意自我隐私保护哦!')
|
23 |
|
|
|
79 |
txt.submit(predict, [txt, top_p, temperature, chatbot, history, systemPromptTxt], [chatbot, history, statusDisplay])
|
80 |
submitBtn.click(predict, [txt, top_p, temperature, chatbot, history, systemPromptTxt], [chatbot, history, statusDisplay], show_progress=True)
|
81 |
for k in functional:
|
82 |
+
functional[k]["Button"].click(predict,
|
83 |
[txt, top_p, temperature, chatbot, history, systemPromptTxt, TRUE, gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
84 |
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
|
85 |
for k in crazy_functional:
|
86 |
+
click_handle = crazy_functional[k]["Button"].click(crazy_functional[k]["Function"],
|
87 |
[txt, top_p, temperature, chatbot, history, systemPromptTxt, gr.State(PORT)], [chatbot, history, statusDisplay]
|
88 |
)
|
89 |
try: click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
|
|
|
91 |
|
92 |
|
93 |
demo.title = "ChatGPT 学术优化"
|
94 |
+
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", share=True, server_port=PORT, inbrowser=True, auth=AUTHENTICATION)
|