diff --git a/config.py b/config.py index a78af65..f4a59de 100644 --- a/config.py +++ b/config.py @@ -62,4 +62,4 @@ AUTHENTICATION = [] API_URL_REDIRECT = {} # 如果你需要把网址放在二级地址下(常规情况下,不要修改!!) -CUSTOM_PATH = "/" +CUSTOM_PATH = "/gra" diff --git a/main.py b/main.py index 11f92f4..ce2c566 100644 --- a/main.py +++ b/main.py @@ -176,18 +176,18 @@ def main(): def auto_opentab_delay(): import threading, webbrowser, time print(f"如果浏览器没有自动打开,请复制并转到以下URL:") - print(f"\t(亮色主题): http://localhost:{PORT}") - print(f"\t(暗色主题): http://localhost:{PORT}/?__dark-theme=true") + print(f"\t(亮色主题): http://localhost:{PORT}" + f"{CUSTOM_PATH}".replace('//','/')) + print(f"\t(暗色主题): http://localhost:{PORT}" + f"{CUSTOM_PATH}/?__dark-theme=true".replace('//','/')) def open(): time.sleep(2) # 打开浏览器 - webbrowser.open_new_tab(f"http://localhost:{PORT}/?__dark-theme=true") + webbrowser.open_new_tab(f"http://localhost:{PORT}" + f"{CUSTOM_PATH}/?__dark-theme=true".replace('//','/')) threading.Thread(target=open, name="open-browser", daemon=True).start() threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start() threading.Thread(target=warm_up_modules, name="warm-up", daemon=True).start() auto_opentab_delay() demo.queue(concurrency_count=CONCURRENT_COUNT) - run_gradio(demo, auth=AUTHENTICATION, favicon_path="docs/logo.png", port=PORT, custom_path=CUSTOM_PATH) + run_gradio(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH) if __name__ == "__main__": main() diff --git a/toolbox.py b/toolbox.py index bf32ccd..cd6c61e 100644 --- a/toolbox.py +++ b/toolbox.py @@ -521,13 +521,14 @@ class DummyWith(): def __exit__(self, exc_type, exc_value, traceback): return -def run_gradio(demo, auth, favicon_path, port, custom_path): +def run_gradio(demo, auth, port, custom_path): import uvicorn import gradio as gr from fastapi import FastAPI app = FastAPI() - @app.get("/") - def read_main(): - return {"message": "NULL"} - app = gr.mount_gradio_app(app, demo, path=custom_path, auth=auth, favicon_path=favicon_path) - uvicorn.run(app, host="0.0.0.0", port=port) + if custom_path != "/": + @app.get("/") + def read_main(): + return {"message": f"Gradio is running at: {custom_path}"} + app = gr.mount_gradio_app(app, demo, path=custom_path) + uvicorn.run(app, host="0.0.0.0", port=port) # , auth=auth