Nathyboy commited on
Commit
14905b7
Β·
verified Β·
1 Parent(s): 5e6ac01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -98,7 +98,7 @@ def start_webui():
98
  port = int(os.environ.get("PORT", 7860))
99
  cmd = ["python", LAUNCH_PY] + shlex.split(WEBUI_ARGS) + [f"--port={port}"]
100
 
101
- # Redirect output to avoid HF spam
102
  with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
103
  if wait_for_port(port, timeout=180):
104
  print(f"βœ… WebUI is ready on port {port}")
@@ -112,11 +112,17 @@ print("🧡 WebUI background thread started.")
112
  # Gradio UI
113
  # -----------------------------
114
  def show_status():
115
- port = int(os.environ.get("PORT", 7860))
116
- space_domain = os.environ.get("SPACE_DOMAIN", "your-space-name.hf.space")
117
- url = f"https://{space_domain}/?__theme=light" # HF public URL
118
  lines = ["βœ… HF Space running (Option B launcher)."]
119
- lines.append(f"WebUI URL (open in browser when ready): {url}")
 
 
 
 
 
 
 
 
 
120
  # Model status
121
  for key, info in DOWNLOADS.items():
122
  present = "yes" if os.path.exists(info["dest"]) else "no"
@@ -130,8 +136,10 @@ with gr.Blocks() as demo:
130
  status_out = gr.Textbox(lines=10)
131
  status_btn.click(fn=show_status, inputs=None, outputs=status_out)
132
 
 
133
  demo.launch(
134
  server_name="0.0.0.0",
135
  server_port=int(os.environ.get("PORT", 7860)),
136
- ssr_mode=False # prevent Node server port issues
 
137
  )
 
98
  port = int(os.environ.get("PORT", 7860))
99
  cmd = ["python", LAUNCH_PY] + shlex.split(WEBUI_ARGS) + [f"--port={port}"]
100
 
101
+ # Redirect output to avoid HF log spam
102
  with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
103
  if wait_for_port(port, timeout=180):
104
  print(f"βœ… WebUI is ready on port {port}")
 
112
  # Gradio UI
113
  # -----------------------------
114
  def show_status():
 
 
 
115
  lines = ["βœ… HF Space running (Option B launcher)."]
116
+
117
+ # Show public shareable URL for the Space WebUI
118
+ try:
119
+ # share=True generates a public URL automatically
120
+ port = int(os.environ.get("PORT", 7860))
121
+ url = demo.share_url # updated after launch
122
+ lines.append(f"WebUI URL (open in browser when ready): {url}")
123
+ except Exception:
124
+ lines.append("WebUI URL not yet available. Refresh after a few seconds.")
125
+
126
  # Model status
127
  for key, info in DOWNLOADS.items():
128
  present = "yes" if os.path.exists(info["dest"]) else "no"
 
136
  status_out = gr.Textbox(lines=10)
137
  status_btn.click(fn=show_status, inputs=None, outputs=status_out)
138
 
139
+ # Launch Gradio with share=True to get a public clickable URL
140
  demo.launch(
141
  server_name="0.0.0.0",
142
  server_port=int(os.environ.get("PORT", 7860)),
143
+ ssr_mode=False,
144
+ share=True # <--- makes the WebUI URL publicly accessible
145
  )