ACE-Step Custom commited on
Commit
55a1124
·
1 Parent(s): ccb3542

Monkey patch get_api_info to prevent JSON schema errors

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -658,22 +658,24 @@ if __name__ == "__main__":
658
  # Create and launch app
659
  app = create_ui()
660
 
661
- # Override /info endpoint to prevent JSON schema errors (must be before launch)
662
- try:
663
- from fastapi.responses import JSONResponse
664
-
665
- @app.app.get("/info")
666
- async def custom_api_info():
667
- """Custom API info endpoint with error handling"""
668
- return JSONResponse(content={
669
- "error": "API schema generation disabled",
670
- "message": "Use the Gradio UI for direct interaction"
671
- })
672
- logger.info(" Overridden /info endpoint")
673
- except Exception as e:
674
- logger.warning(f"Could not override /info endpoint: {e}")
675
-
676
- # Launch with API mode disabled to prevent JSON schema errors
 
 
677
  app.launch(
678
  server_name="0.0.0.0",
679
  server_port=7860,
 
658
  # Create and launch app
659
  app = create_ui()
660
 
661
+ # Monkey patch the get_api_info method to prevent JSON schema errors
662
+ original_get_api_info = app.get_api_info
663
+
664
+ def safe_get_api_info(*args, **kwargs):
665
+ """Patched get_api_info that returns minimal info to avoid schema errors"""
666
+ try:
667
+ return original_get_api_info(*args, **kwargs)
668
+ except (TypeError, AttributeError, KeyError) as e:
669
+ logger.warning(f"API info generation failed, returning minimal info: {e}")
670
+ return {
671
+ "named_endpoints": {},
672
+ "unnamed_endpoints": {}
673
+ }
674
+
675
+ app.get_api_info = safe_get_api_info
676
+ logger.info("✓ Patched get_api_info method")
677
+
678
+ # Launch the app
679
  app.launch(
680
  server_name="0.0.0.0",
681
  server_port=7860,