import os import gradio as gr def _launch(): # HF Spaces/Gradio sometimes calls /api_info regardless of `show_api=False`. # Some gradio_client versions crash when JSON schema uses boolean `additionalProperties`. # Patch defensively to avoid bringing down the whole app. try: import gradio_client.utils as _gcu if hasattr(_gcu, "_json_schema_to_python_type"): _orig = _gcu._json_schema_to_python_type def _json_schema_to_python_type_patched(schema, defs=None): if isinstance(schema, bool): return "Any" return _orig(schema, defs) _gcu._json_schema_to_python_type = _json_schema_to_python_type_patched except Exception: pass # HF Spaces expects the app to listen on 0.0.0.0:7860 (PORT may be provided). import mvp port = int(os.getenv("PORT", "7860")) # `mvp` defines `demo` (gr.Blocks). We launch it here instead of inside `mvp.py`. mvp.demo.queue(max_size=20).launch( server_name="0.0.0.0", server_port=port, show_error=True, share=False, show_api=False, ) if __name__ == "__main__": _launch()