Nymbo commited on
Commit
428950f
·
verified ·
1 Parent(s): bae3e9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -530,11 +530,21 @@ def _public_file_url(local_path: str) -> str:
530
  from urllib.parse import quote
531
  host = os.getenv("SPACE_HOST", "").strip()
532
  abs_path = os.path.abspath(local_path)
533
- quoted = quote(abs_path)
534
- if host:
 
 
 
 
 
 
 
 
535
  return f"https://{host}/file={quoted}"
536
- # Local/dev fallback
537
- return f"/file={quoted}"
 
 
538
  except Exception:
539
  # Last-resort: return the original path to avoid breaking UI
540
  return local_path
@@ -2190,7 +2200,7 @@ def Generate_Video( # <-- MCP tool #6 (Generate Video)
2190
  size = os.path.getsize(path)
2191
  except Exception:
2192
  size = -1
2193
- # Always publish HF Space absolute URL to avoid proxy hosts (e.g., mcp.nymbo.net)
2194
  url = _public_file_url(path)
2195
  _log_call_end("Generate_Video", f"provider={provider} path={os.path.basename(path)} bytes={size} url={url}")
2196
  return url
@@ -2730,7 +2740,8 @@ def Deep_Research(
2730
  file_url = _public_file_url(file_path)
2731
  # Append a canonical HF download link so clients avoid proxy origins when clicking
2732
  try:
2733
- report = report.rstrip() + f"\n\n---\nDownload the full report as text: [research_report.txt]({file_url})\n"
 
2734
  except Exception:
2735
  pass
2736
  elapsed = time.time() - start_ts
 
530
  from urllib.parse import quote
531
  host = os.getenv("SPACE_HOST", "").strip()
532
  abs_path = os.path.abspath(local_path)
533
+
534
+ # Detect Windows absolute path (e.g., C:\...) or running on Windows
535
+ is_windows_path = bool(re.match(r"^[a-zA-Z]:\\", abs_path)) or os.name == "nt"
536
+ is_posix_abs = abs_path.startswith("/")
537
+
538
+ # Only construct an absolute hf.space URL when:
539
+ # - We have a SPACE_HOST
540
+ # - The file path is POSIX-absolute (we're running inside the Space container)
541
+ if host and is_posix_abs and not is_windows_path:
542
+ quoted = quote(abs_path)
543
  return f"https://{host}/file={quoted}"
544
+
545
+ # Otherwise, prefer returning the raw path and let Gradio serve it in the same origin
546
+ # (UI components like gr.File/gr.Video handle this).
547
+ return local_path
548
  except Exception:
549
  # Last-resort: return the original path to avoid breaking UI
550
  return local_path
 
2200
  size = os.path.getsize(path)
2201
  except Exception:
2202
  size = -1
2203
+ # Prefer HF Space absolute URL when running in a Space, otherwise return local path
2204
  url = _public_file_url(path)
2205
  _log_call_end("Generate_Video", f"provider={provider} path={os.path.basename(path)} bytes={size} url={url}")
2206
  return url
 
2740
  file_url = _public_file_url(file_path)
2741
  # Append a canonical HF download link so clients avoid proxy origins when clicking
2742
  try:
2743
+ if isinstance(file_url, str) and file_url.startswith("http"):
2744
+ report = report.rstrip() + f"\n\n---\nDownload the full report as text: [research_report.txt]({file_url})\n"
2745
  except Exception:
2746
  pass
2747
  elapsed = time.time() - start_ts