Merge branch 'subpath'
This commit is contained in:
commit
33ea7391b5
@ -60,3 +60,6 @@ AUTHENTICATION = []
|
|||||||
# 重新URL重新定向,实现更换API_URL的作用(常规情况下,不要修改!!)
|
# 重新URL重新定向,实现更换API_URL的作用(常规情况下,不要修改!!)
|
||||||
# 格式 {"https://api.openai.com/v1/chat/completions": "重定向的URL"}
|
# 格式 {"https://api.openai.com/v1/chat/completions": "重定向的URL"}
|
||||||
API_URL_REDIRECT = {}
|
API_URL_REDIRECT = {}
|
||||||
|
|
||||||
|
# 如果你需要把网址放在二级地址下(常规情况下,不要修改!!)(需要配合修改main.py才能生效)
|
||||||
|
CUSTOM_PATH = "/"
|
||||||
|
8
main.py
8
main.py
@ -188,5 +188,13 @@ def main():
|
|||||||
auto_opentab_delay()
|
auto_opentab_delay()
|
||||||
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png")
|
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png")
|
||||||
|
|
||||||
|
# 如果需要在二级路径下运行gradio
|
||||||
|
# CUSTOM_PATH, = get_conf('CUSTOM_PATH')
|
||||||
|
# if CUSTOM_PATH != "/":
|
||||||
|
# from toolbox import run_gradio_in_subpath
|
||||||
|
# run_gradio_in_subpath(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH)
|
||||||
|
# else:
|
||||||
|
# demo.launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
31
toolbox.py
31
toolbox.py
@ -520,3 +520,34 @@ class DummyWith():
|
|||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def run_gradio_in_subpath(demo, auth, port, custom_path):
|
||||||
|
def is_path_legal(path: str)->bool:
|
||||||
|
'''
|
||||||
|
check path for sub url
|
||||||
|
path: path to check
|
||||||
|
return value: do sub url wrap
|
||||||
|
'''
|
||||||
|
if path == "/": return True
|
||||||
|
if len(path) == 0:
|
||||||
|
print("ilegal custom path: {}\npath must not be empty\ndeploy on root url".format(path))
|
||||||
|
return False
|
||||||
|
if path[0] == '/':
|
||||||
|
if path[1] != '/':
|
||||||
|
print("deploy on sub-path {}".format(path))
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
print("ilegal custom path: {}\npath should begin with \'/\'\ndeploy on root url".format(path))
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not is_path_legal(custom_path): raise RuntimeError('Ilegal custom path')
|
||||||
|
import uvicorn
|
||||||
|
import gradio as gr
|
||||||
|
from fastapi import FastAPI
|
||||||
|
app = FastAPI()
|
||||||
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user