Spaces:
Runtime error
Runtime error
add check path back
Browse files- config.py +1 -1
- toolbox.py +19 -0
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 = "/"
|
toolbox.py
CHANGED
|
@@ -522,6 +522,25 @@ class DummyWith():
|
|
| 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
|
|
|
|
| 522 |
return
|
| 523 |
|
| 524 |
def run_gradio(demo, auth, port, custom_path):
|
| 525 |
+
def is_path_legal(path: str)->bool:
|
| 526 |
+
'''
|
| 527 |
+
check path for sub url
|
| 528 |
+
path: path to check
|
| 529 |
+
return value: do sub url wrap
|
| 530 |
+
'''
|
| 531 |
+
if path == "/": return True
|
| 532 |
+
if len(path) == 0:
|
| 533 |
+
print("ilegal custom path: {}\npath must not be empty\ndeploy on root url".format(path))
|
| 534 |
+
return False
|
| 535 |
+
if path[0] == '/':
|
| 536 |
+
if path[1] != '/':
|
| 537 |
+
print("deploy on sub-path {}".format(path))
|
| 538 |
+
return True
|
| 539 |
+
return False
|
| 540 |
+
print("ilegal custom path: {}\npath should begin with \'/\'\ndeploy on root url".format(path))
|
| 541 |
+
return False
|
| 542 |
+
|
| 543 |
+
if not is_path_legal(custom_path): raise RuntimeError('Ilegal custom path')
|
| 544 |
import uvicorn
|
| 545 |
import gradio as gr
|
| 546 |
from fastapi import FastAPI
|