johnnychiang commited on
Commit
e630cfe
·
verified ·
1 Parent(s): 9ccc416

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -27,6 +27,26 @@ def _http_get(url: str, timeout: int = 30, stream: bool = False) -> requests.Res
27
  headers={"User-Agent": "Mozilla/5.0", "Accept": "*/*"},
28
  )
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  def _looks_like_html(b: bytes) -> bool:
32
  head = b[:400].lower()
@@ -592,6 +612,7 @@ class BasicAgent:
592
  def run_and_submit_all(profile: gr.OAuthProfile | None = None):
593
  try:
594
  space_id = os.getenv("SPACE_ID", "").strip()
 
595
 
596
  if profile and getattr(profile, "username", None):
597
  username = profile.username
 
27
  headers={"User-Agent": "Mozilla/5.0", "Accept": "*/*"},
28
  )
29
 
30
+ def probe_api(api_url: str) -> str:
31
+ paths = [
32
+ "/", "/config", "/info", "/openapi.json", "/docs", "/redoc",
33
+ "/gradio_api/info", "/gradio_api/config", "/gradio_api/openapi.json",
34
+ "/api", "/api/openapi.json"
35
+ ]
36
+ logs = []
37
+ for p in paths:
38
+ url = api_url.rstrip("/") + p
39
+ try:
40
+ r = requests.get(url, timeout=15)
41
+ ct = (r.headers.get("content-type") or "").lower()
42
+ logs.append(f"{r.status_code} {url} ({ct})")
43
+ if r.status_code == 200:
44
+ # 只印前 400 字,避免爆版
45
+ txt = r.text[:400].replace("\n", "\\n")
46
+ logs.append(" BODY_HEAD: " + txt)
47
+ except Exception as e:
48
+ logs.append(f"ERR {url} :: {type(e).__name__}: {e}")
49
+ return "\n".join(logs)
50
 
51
  def _looks_like_html(b: bytes) -> bool:
52
  head = b[:400].lower()
 
612
  def run_and_submit_all(profile: gr.OAuthProfile | None = None):
613
  try:
614
  space_id = os.getenv("SPACE_ID", "").strip()
615
+ print(probe_api(DEFAULT_API_URL))
616
 
617
  if profile and getattr(profile, "username", None):
618
  username = profile.username