Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,30 +25,34 @@ starlette.templating.Jinja2Templates.TemplateResponse = _patched_template_respon
|
|
| 25 |
|
| 26 |
|
| 27 |
# ββ Patch the gradio_client JSON-schema parser crash safely ββββββββββββββββββ
|
| 28 |
-
import
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
|
| 32 |
-
def
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
if
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
import pandas as pd
|
|
@@ -657,15 +661,11 @@ def build_app():
|
|
| 657 |
# Entry point
|
| 658 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 659 |
|
| 660 |
-
# Build the app at module level so Hugging Face Spaces can import it correctly.
|
| 661 |
-
# The `if __name__ == "__main__"` guard prevented launch() from running on Spaces
|
| 662 |
-
# because HF imports app.py rather than executing it as a script.
|
| 663 |
app = build_app()
|
| 664 |
-
_on_spaces = os.environ.get("SPACE_ID") is not None
|
| 665 |
|
| 666 |
app.launch(
|
| 667 |
server_name="0.0.0.0",
|
| 668 |
server_port=7860,
|
| 669 |
-
share=
|
| 670 |
show_error=True
|
| 671 |
)
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
# ββ Patch the gradio_client JSON-schema parser crash safely ββββββββββββββββββ
|
| 28 |
+
import gradio_client.utils as gc_utils
|
| 29 |
+
import copy
|
| 30 |
|
| 31 |
+
_original_parser = gc_utils._json_schema_to_python_type
|
| 32 |
|
| 33 |
+
def _patched_parser(schema):
|
| 34 |
+
try:
|
| 35 |
+
# Deepcopy to avoid mutating the original schema object
|
| 36 |
+
safe_schema = copy.deepcopy(schema)
|
| 37 |
+
|
| 38 |
+
# Recursively hunt down and replace boolean additionalProperties
|
| 39 |
+
def fix_booleans(obj):
|
| 40 |
+
if isinstance(obj, dict):
|
| 41 |
+
if "additionalProperties" in obj and isinstance(obj["additionalProperties"], bool):
|
| 42 |
+
obj["additionalProperties"] = {}
|
| 43 |
+
for v in obj.values():
|
| 44 |
+
fix_booleans(v)
|
| 45 |
+
elif isinstance(obj, list):
|
| 46 |
+
for item in obj:
|
| 47 |
+
fix_booleans(item)
|
| 48 |
+
|
| 49 |
+
fix_booleans(safe_schema)
|
| 50 |
+
return _original_parser(safe_schema)
|
| 51 |
+
except Exception:
|
| 52 |
+
# Fallback to the original schema if our scrubber fails
|
| 53 |
+
return _original_parser(schema)
|
| 54 |
+
|
| 55 |
+
gc_utils._json_schema_to_python_type = _patched_parser
|
| 56 |
|
| 57 |
|
| 58 |
import pandas as pd
|
|
|
|
| 661 |
# Entry point
|
| 662 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 663 |
|
|
|
|
|
|
|
|
|
|
| 664 |
app = build_app()
|
|
|
|
| 665 |
|
| 666 |
app.launch(
|
| 667 |
server_name="0.0.0.0",
|
| 668 |
server_port=7860,
|
| 669 |
+
share=False,
|
| 670 |
show_error=True
|
| 671 |
)
|