Shim commited on
Commit
37545aa
Β·
1 Parent(s): 77244ea

Unify local and HF Spaces experience with improved launch configuration

Browse files
Files changed (1) hide show
  1. app.py +27 -15
app.py CHANGED
@@ -529,28 +529,40 @@ def main():
529
  app = MirautrApp()
530
  demo = app.create_main_interface()
531
 
532
- # Launch configuration optimized for HF Spaces
533
  is_hf_spaces = os.getenv("SPACE_ID") is not None
534
 
535
  logger.info(f"Launching app... HF Spaces: {is_hf_spaces}")
536
 
 
 
 
 
 
 
 
 
 
537
  if is_hf_spaces:
538
- # HF Spaces configuration - simplified
539
  logger.info("Configuring for HF Spaces deployment")
540
- demo.launch(
541
- server_name="0.0.0.0",
542
- server_port=7860,
543
- show_error=True,
544
- quiet=False
545
- )
546
  else:
547
- # Local development configuration
548
- demo.launch(
549
- server_name="0.0.0.0",
550
- server_port=7860,
551
- share=False,
552
- show_error=True
553
- )
 
 
 
554
 
555
  except Exception as e:
556
  logger.error(f"Failed to start application: {e}")
 
529
  app = MirautrApp()
530
  demo = app.create_main_interface()
531
 
532
+ # Check environment
533
  is_hf_spaces = os.getenv("SPACE_ID") is not None
534
 
535
  logger.info(f"Launching app... HF Spaces: {is_hf_spaces}")
536
 
537
+ # Unified launch configuration for both environments
538
+ # This ensures identical experience in both local and HF Spaces
539
+ launch_config = {
540
+ "show_error": True,
541
+ "show_api": False, # Disable API docs to avoid schema issues
542
+ "favicon_path": None,
543
+ "auth": None
544
+ }
545
+
546
  if is_hf_spaces:
547
+ # HF Spaces specific settings
548
  logger.info("Configuring for HF Spaces deployment")
549
+ launch_config.update({
550
+ "server_name": "0.0.0.0",
551
+ "server_port": 7860,
552
+ "share": False, # HF Spaces handles public access
553
+ "quiet": True
554
+ })
555
  else:
556
+ # Local development settings
557
+ logger.info("Configuring for local development")
558
+ launch_config.update({
559
+ "server_name": "127.0.0.1",
560
+ "server_port": int(os.getenv("GRADIO_SERVER_PORT", "7860")),
561
+ "share": True, # Create public link for local testing
562
+ "quiet": False
563
+ })
564
+
565
+ demo.launch(**launch_config)
566
 
567
  except Exception as e:
568
  logger.error(f"Failed to start application: {e}")