staraks commited on
Commit
1910810
·
verified ·
1 Parent(s): 5bbecec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -523,3 +523,34 @@ if __name__ == "__main__":
523
  print("FATAL: demo.launch failed:", e, flush=True)
524
  traceback.print_exc()
525
  raise
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
  print("FATAL: demo.launch failed:", e, flush=True)
524
  traceback.print_exc()
525
  raise
526
+
527
+
528
+
529
+
530
+ # Safe launch: only launch if demo exists
531
+ if __name__ == "__main__":
532
+ port = int(os.environ.get("PORT", 7860))
533
+ print("DEBUG: preparing to launch Gradio on port", port, flush=True)
534
+ try:
535
+ if 'demo' in globals() and demo is not None:
536
+ print("DEBUG: demo object found. launching...", flush=True)
537
+ demo.queue().launch(server_name="0.0.0.0", server_port=port)
538
+ else:
539
+ print("FATAL: 'demo' not found. The Gradio UI block may be missing or failed to create.", flush=True)
540
+ # show the tail of the file so you can inspect quickly in logs
541
+ try:
542
+ import inspect
543
+ import pathlib
544
+ print("DEBUG: last 60 lines of /app/app.py for inspection:", flush=True)
545
+ with open("/app/app.py", "r", encoding="utf-8") as fh:
546
+ all_lines = fh.read().splitlines()
547
+ for ln in all_lines[-60:]:
548
+ print(ln)
549
+ except Exception:
550
+ pass
551
+ # Exit non-zero so platform reports failure clearly
552
+ sys.exit(1)
553
+ except Exception as e:
554
+ print("FATAL: demo.launch failed:", e, flush=True)
555
+ traceback.print_exc()
556
+ raise