Bryceeee commited on
Commit
d080b90
Β·
verified Β·
1 Parent(s): 7964505

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -239,25 +239,24 @@ def create_app():
239
  # Spaces will automatically detect Gradio and run this
240
  # The demo variable must be exposed at module level for Spaces to detect it
241
 
242
- # Initialize demo to None first
243
- demo = None
 
244
 
245
- # Only initialize once (prevent duplicate initialization)
246
- if demo is None:
247
- try:
248
- print("πŸ”„ Starting app initialization...")
249
- demo = create_app()
250
- print("βœ… App created successfully!")
251
- print(f"βœ… Demo type: {type(demo)}")
252
- print(f"βœ… Demo object: {demo}")
 
 
 
 
253
 
254
- # Verify demo is a valid Gradio Blocks object
255
- if demo is None:
256
- raise ValueError("Demo object is None after creation")
257
- if not hasattr(demo, 'launch'):
258
- raise ValueError("Demo object does not have launch method")
259
-
260
- except Exception as e:
261
  print(f"❌ Fatal error creating app: {e}")
262
  import traceback
263
  traceback.print_exc()
@@ -290,8 +289,8 @@ if demo is None:
290
  description="An error occurred. Please check the logs."
291
  )
292
 
293
- # Final verification
294
- if demo is None:
295
  import gradio as gr
296
  demo = gr.Interface(
297
  fn=lambda: "Application failed to initialize. Please check the logs.",
 
239
  # Spaces will automatically detect Gradio and run this
240
  # The demo variable must be exposed at module level for Spaces to detect it
241
 
242
+ # Create demo object for Hugging Face Spaces
243
+ # Spaces will automatically detect and launch the demo object
244
+ # We use a simple approach: create demo directly at module level
245
 
246
+ try:
247
+ print("πŸ”„ Starting app initialization...")
248
+ demo = create_app()
249
+ print("βœ… App created successfully!")
250
+ print(f"βœ… Demo type: {type(demo)}")
251
+ print(f"βœ… Demo object: {demo}")
252
+
253
+ # Verify demo is a valid Gradio Blocks object
254
+ if demo is None:
255
+ raise ValueError("Demo object is None after creation")
256
+ if not hasattr(demo, 'launch'):
257
+ raise ValueError("Demo object does not have launch method")
258
 
259
+ except Exception as e:
 
 
 
 
 
 
260
  print(f"❌ Fatal error creating app: {e}")
261
  import traceback
262
  traceback.print_exc()
 
289
  description="An error occurred. Please check the logs."
290
  )
291
 
292
+ # Ensure demo is always defined (fallback if all else fails)
293
+ if 'demo' not in globals() or demo is None:
294
  import gradio as gr
295
  demo = gr.Interface(
296
  fn=lambda: "Application failed to initialize. Please check the logs.",