File size: 1,206 Bytes
6c099d4 52f5401 6c099d4 e7e26ca 6c099d4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
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()
|