""" Hugging Face Spaces entrypoint for the DRIVE/RLDT Gradio interface. The script keeps dependencies lightweight and reuses the existing ``create_gradio_interface`` factory so Spaces can discover the app without command-line flags. Environment variable support mirrors the CLI path in ``RL0910/enhanced_chat_ui.py``. """ try: import gradio_client.utils as gcu _orig = gcu._json_schema_to_python_type def _patched_json_schema_to_python_type(schema, defs=None): # Some JSON Schema emit literal True/False (esp. with newer pydantic) if schema is True: return "Any" if schema is False or schema is None: return "Any" # additionalProperties may be boolean in JSON Schema; gradio_client may choke if isinstance(schema, dict): ap = schema.get("additionalProperties", None) if isinstance(ap, bool): schema = dict(schema) schema["additionalProperties"] = {} # treat as "any object" try: return _orig(schema, defs) except Exception: # Conservative fallback: don't crash API info return "Any" gcu._json_schema_to_python_type = _patched_json_schema_to_python_type except Exception: # If anything changes upstream, don't block the app from starting. pass import os # Align pandas behaviour with the main UI module before it gets imported. os.environ.setdefault("PANDAS_USE_PYARROW_BACKEND", "0") os.environ.setdefault("PANDAS_USE_PYARROW_EXTENSION_ARRAY", "0") from RL0910.enhanced_chat_ui import create_gradio_interface try: import gradio_client.utils as _gcu if not getattr(_gcu, "_BOOL_SCHEMA_PATCHED", False): _orig_get_type = _gcu.get_type def _patched_get_type(schema): # JSON Schema allows boolean schemas (True/False). gradio_client assumed dict. if isinstance(schema, bool): # Treat boolean schema as "Any" to keep api schema generation alive return "Any" return _orig_get_type(schema) _gcu.get_type = _patched_get_type _gcu._BOOL_SCHEMA_PATCHED = True except Exception: # Never block app startup due to a patch attempt pass # Create the Gradio app for Spaces discovery. demo = create_gradio_interface() def main() -> None: """Launch the Gradio demo on the port provided by Hugging Face Spaces.""" port = int(os.getenv("PORT", "7860")) demo.launch(server_name="0.0.0.0", server_port=port, share=False) if __name__ == "__main__": main()