Melatonini commited on
Commit
d86fd07
·
1 Parent(s): ff48b6d

Fix Hugging Face Space blank UI: disable SSR via env, extend startup timeout.

Browse files

Remove gradio from requirements (Space pins it), lazy-load agent for faster boot, and bind server to 0.0.0.0:7860.

Files changed (3) hide show
  1. README.md +1 -0
  2. app.py +16 -24
  3. requirements.txt +0 -1
README.md CHANGED
@@ -7,6 +7,7 @@ sdk: gradio
7
  sdk_version: 5.25.2
8
  app_file: app.py
9
  pinned: false
 
10
  hf_oauth: true
11
  # optional, default duration is 8 hours/480 minutes. Max duration is 30 days/43200 minutes.
12
  hf_oauth_expiration_minutes: 480
 
7
  sdk_version: 5.25.2
8
  app_file: app.py
9
  pinned: false
10
+ startup_duration_timeout: 1h
11
  hf_oauth: true
12
  # optional, default duration is 8 hours/480 minutes. Max duration is 30 days/43200 minutes.
13
  hf_oauth_expiration_minutes: 480
app.py CHANGED
@@ -4,7 +4,6 @@ import gradio as gr
4
  import pandas as pd
5
  import requests
6
 
7
- from agent import BasicAgent
8
  from files import download_task_file
9
 
10
  # (Keep Constants as is)
@@ -32,6 +31,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
32
 
33
  # 1. Instantiate Agent ( modify this part to create your agent)
34
  try:
 
 
35
  agent = BasicAgent()
36
  except Exception as e:
37
  print(f"Error instantiating agent: {e}")
@@ -176,29 +177,20 @@ with gr.Blocks() as demo:
176
  )
177
 
178
  if __name__ == "__main__":
179
- print("\n" + "-"*30 + " App Starting " + "-"*30)
180
- # Check for SPACE_HOST and SPACE_ID at startup for information
181
  space_host_startup = os.getenv("SPACE_HOST")
182
- space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
183
 
 
184
  if space_host_startup:
185
- print(f"SPACE_HOST found: {space_host_startup}")
186
- print(f" Runtime URL should be: https://{space_host_startup}")
187
- else:
188
- print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
189
-
190
- if space_id_startup: # Print repo URLs if SPACE_ID is found
191
- print(f"✅ SPACE_ID found: {space_id_startup}")
192
- print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
193
- print(f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main")
194
- else:
195
- print("ℹ️ SPACE_ID environment variable not found (running locally?). Repo URL cannot be determined.")
196
-
197
- print("-"*(60 + len(" App Starting ")) + "\n")
198
-
199
- print("Launching Gradio Interface for Basic Agent Evaluation...")
200
- on_space = bool(space_id_startup)
201
- launch_kwargs = {"debug": not on_space, "share": False}
202
- if on_space:
203
- launch_kwargs["ssr_mode"] = False
204
- demo.launch(**launch_kwargs)
 
4
  import pandas as pd
5
  import requests
6
 
 
7
  from files import download_task_file
8
 
9
  # (Keep Constants as is)
 
31
 
32
  # 1. Instantiate Agent ( modify this part to create your agent)
33
  try:
34
+ from agent import BasicAgent
35
+
36
  agent = BasicAgent()
37
  except Exception as e:
38
  print(f"Error instantiating agent: {e}")
 
177
  )
178
 
179
  if __name__ == "__main__":
180
+ space_id_startup = os.getenv("SPACE_ID")
 
181
  space_host_startup = os.getenv("SPACE_HOST")
 
182
 
183
+ print("\n" + "-" * 30 + " App Starting " + "-" * 30)
184
  if space_host_startup:
185
+ print(f"SPACE_HOST found: {space_host_startup}")
186
+ print(f"Runtime URL: https://{space_host_startup}")
187
+ if space_id_startup:
188
+ print(f"SPACE_ID found: {space_id_startup}")
189
+ print("-" * 60 + "\n")
190
+
191
+ demo.launch(
192
+ server_name="0.0.0.0",
193
+ server_port=7860,
194
+ debug=not bool(space_id_startup),
195
+ share=False,
196
+ )
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
- gradio[oauth]
2
  requests
3
  pandas
4
  smolagents
 
 
1
  requests
2
  pandas
3
  smolagents