3v324v23 commited on
Commit
7beea95
1 Parent(s): 6f7e807

unifying code

Browse files
Files changed (3) hide show
  1. config.py +1 -1
  2. main.py +4 -4
  3. toolbox.py +7 -6
config.py CHANGED
@@ -62,4 +62,4 @@ AUTHENTICATION = []
62
  API_URL_REDIRECT = {}
63
 
64
  # 如果你需要把网址放在二级地址下(常规情况下,不要修改!!)
65
- CUSTOM_PATH = "/"
 
62
  API_URL_REDIRECT = {}
63
 
64
  # 如果你需要把网址放在二级地址下(常规情况下,不要修改!!)
65
+ CUSTOM_PATH = "/gra"
main.py CHANGED
@@ -176,18 +176,18 @@ 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}/?__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)
190
- run_gradio(demo, auth=AUTHENTICATION, favicon_path="docs/logo.png", port=PORT, custom_path=CUSTOM_PATH)
191
 
192
  if __name__ == "__main__":
193
  main()
 
176
  def auto_opentab_delay():
177
  import threading, webbrowser, time
178
  print(f"如果浏览器没有自动打开,请复制并转到以下URL:")
179
+ print(f"\t(亮色主题): http://localhost:{PORT}" + f"{CUSTOM_PATH}".replace('//','/'))
180
+ print(f"\t(暗色主题): http://localhost:{PORT}" + f"{CUSTOM_PATH}/?__dark-theme=true".replace('//','/'))
181
  def open():
182
  time.sleep(2) # 打开浏览器
183
+ webbrowser.open_new_tab(f"http://localhost:{PORT}" + f"{CUSTOM_PATH}/?__dark-theme=true".replace('//','/'))
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
+ run_gradio(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH)
191
 
192
  if __name__ == "__main__":
193
  main()
toolbox.py CHANGED
@@ -521,13 +521,14 @@ class DummyWith():
521
  def __exit__(self, exc_type, exc_value, traceback):
522
  return
523
 
524
- def run_gradio(demo, auth, favicon_path, port, custom_path):
525
  import uvicorn
526
  import gradio as gr
527
  from fastapi import FastAPI
528
  app = FastAPI()
529
- @app.get("/")
530
- def read_main():
531
- return {"message": "NULL"}
532
- app = gr.mount_gradio_app(app, demo, path=custom_path, auth=auth, favicon_path=favicon_path)
533
- uvicorn.run(app, host="0.0.0.0", port=port)
 
 
521
  def __exit__(self, exc_type, exc_value, traceback):
522
  return
523
 
524
+ def run_gradio(demo, auth, port, custom_path):
525
  import uvicorn
526
  import gradio as gr
527
  from fastapi import FastAPI
528
  app = FastAPI()
529
+ if custom_path != "/":
530
+ @app.get("/")
531
+ def read_main():
532
+ return {"message": f"Gradio is running at: {custom_path}"}
533
+ app = gr.mount_gradio_app(app, demo, path=custom_path)
534
+ uvicorn.run(app, host="0.0.0.0", port=port) # , auth=auth