Spaces:
Sleeping
Sleeping
加入subpath支持,但暂不启用
Browse files- config.py +1 -1
- main.py +15 -10
- toolbox.py +1 -1
config.py
CHANGED
@@ -61,5 +61,5 @@ AUTHENTICATION = []
|
|
61 |
# 格式 {"https://api.openai.com/v1/chat/completions": "重定向的URL"}
|
62 |
API_URL_REDIRECT = {}
|
63 |
|
64 |
-
#
|
65 |
CUSTOM_PATH = "/"
|
|
|
61 |
# 格式 {"https://api.openai.com/v1/chat/completions": "重定向的URL"}
|
62 |
API_URL_REDIRECT = {}
|
63 |
|
64 |
+
# 如果你需要把网址放在二级地址下(常规情况下,不要修改!!)(需要配合修改main.py才能生效)
|
65 |
CUSTOM_PATH = "/"
|
main.py
CHANGED
@@ -3,10 +3,10 @@ import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
|
3 |
def main():
|
4 |
import gradio as gr
|
5 |
from request_llm.bridge_all import predict
|
6 |
-
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper,
|
7 |
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
8 |
-
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, API_KEY, AVAIL_LLM_MODELS
|
9 |
-
get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'CHATBOT_HEIGHT', 'LAYOUT', 'API_KEY', 'AVAIL_LLM_MODELS'
|
10 |
|
11 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
12 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
@@ -176,20 +176,25 @@ def main():
|
|
176 |
def auto_opentab_delay():
|
177 |
import threading, webbrowser, time
|
178 |
print(f"如果浏览器没有自动打开,请复制并转到以下URL:")
|
179 |
-
print(f"\t(亮色主题): http://localhost:{PORT}"
|
180 |
-
print(f"\t(暗色主题): http://localhost:{PORT}
|
181 |
def open():
|
182 |
time.sleep(2) # 打开浏览器
|
183 |
-
webbrowser.open_new_tab(f"http://localhost:{PORT}
|
184 |
threading.Thread(target=open, name="open-browser", daemon=True).start()
|
185 |
threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start()
|
186 |
threading.Thread(target=warm_up_modules, name="warm-up", daemon=True).start()
|
187 |
|
188 |
auto_opentab_delay()
|
189 |
-
demo.queue(concurrency_count=CONCURRENT_COUNT)
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
if __name__ == "__main__":
|
193 |
main()
|
194 |
-
|
195 |
-
|
|
|
3 |
def main():
|
4 |
import gradio as gr
|
5 |
from request_llm.bridge_all import predict
|
6 |
+
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, DummyWith
|
7 |
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
8 |
+
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, API_KEY, AVAIL_LLM_MODELS = \
|
9 |
+
get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'CHATBOT_HEIGHT', 'LAYOUT', 'API_KEY', 'AVAIL_LLM_MODELS')
|
10 |
|
11 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
12 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
|
|
176 |
def auto_opentab_delay():
|
177 |
import threading, webbrowser, time
|
178 |
print(f"如果浏览器没有自动打开,请复制并转到以下URL:")
|
179 |
+
print(f"\t(亮色主题): http://localhost:{PORT}")
|
180 |
+
print(f"\t(暗色主题): http://localhost:{PORT}/?__dark-theme=true")
|
181 |
def open():
|
182 |
time.sleep(2) # 打开浏览器
|
183 |
+
webbrowser.open_new_tab(f"http://localhost:{PORT}/?__dark-theme=true")
|
184 |
threading.Thread(target=open, name="open-browser", daemon=True).start()
|
185 |
threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start()
|
186 |
threading.Thread(target=warm_up_modules, name="warm-up", daemon=True).start()
|
187 |
|
188 |
auto_opentab_delay()
|
189 |
+
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png")
|
190 |
+
|
191 |
+
# 如果需要在二级路径下运行gradio
|
192 |
+
# CUSTOM_PATH, = get_conf('CUSTOM_PATH')
|
193 |
+
# if CUSTOM_PATH != "/":
|
194 |
+
# from toolbox import run_gradio_in_subpath
|
195 |
+
# run_gradio_in_subpath(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH)
|
196 |
+
# else:
|
197 |
+
# demo.launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png")
|
198 |
|
199 |
if __name__ == "__main__":
|
200 |
main()
|
|
|
|
toolbox.py
CHANGED
@@ -521,7 +521,7 @@ class DummyWith():
|
|
521 |
def __exit__(self, exc_type, exc_value, traceback):
|
522 |
return
|
523 |
|
524 |
-
def
|
525 |
def is_path_legal(path: str)->bool:
|
526 |
'''
|
527 |
check path for sub url
|
|
|
521 |
def __exit__(self, exc_type, exc_value, traceback):
|
522 |
return
|
523 |
|
524 |
+
def run_gradio_in_subpath(demo, auth, port, custom_path):
|
525 |
def is_path_legal(path: str)->bool:
|
526 |
'''
|
527 |
check path for sub url
|