Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,15 @@ import os
|
|
| 5 |
os.environ.pop("GRADIO_HOT_RELOAD", None)
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
import pandas as pd
|
| 12 |
import json
|
| 13 |
from pathlib import Path
|
|
@@ -618,10 +624,12 @@ def build_app():
|
|
| 618 |
# The `if __name__ == "__main__"` guard prevented launch() from running on Spaces
|
| 619 |
# because HF imports app.py rather than executing it as a script.
|
| 620 |
app = build_app()
|
|
|
|
|
|
|
| 621 |
app.launch(
|
| 622 |
server_name="0.0.0.0",
|
| 623 |
server_port=7860,
|
| 624 |
-
share=
|
| 625 |
show_error=True,
|
| 626 |
prevent_thread_lock=True, # stops Gradio pinging localhost β needed on HF Spaces
|
| 627 |
)
|
|
|
|
| 5 |
os.environ.pop("GRADIO_HOT_RELOAD", None)
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
+
# ββ Patch the broken gradio_client JSON-schema parser ββββββββββββββββββββββββ
|
| 9 |
+
# gradio/routes.py calls `app.get_blocks().get_api_info()` on every /info
|
| 10 |
+
# request. gradio_client.utils._json_schema_to_python_type crashes when
|
| 11 |
+
# `additionalProperties` is a plain bool (True/False) instead of a dict,
|
| 12 |
+
# raising "TypeError: argument of type 'bool' is not iterable".
|
| 13 |
+
# We silence it by making get_api_info() return an empty dict instead.
|
| 14 |
+
import gradio.blocks as _gr_blocks
|
| 15 |
+
_gr_blocks.Blocks.get_api_info = lambda self, *a, **kw: {}
|
| 16 |
+
|
| 17 |
import pandas as pd
|
| 18 |
import json
|
| 19 |
from pathlib import Path
|
|
|
|
| 624 |
# The `if __name__ == "__main__"` guard prevented launch() from running on Spaces
|
| 625 |
# because HF imports app.py rather than executing it as a script.
|
| 626 |
app = build_app()
|
| 627 |
+
_on_spaces = os.environ.get("SPACE_ID") is not None
|
| 628 |
+
|
| 629 |
app.launch(
|
| 630 |
server_name="0.0.0.0",
|
| 631 |
server_port=7860,
|
| 632 |
+
share=_on_spaces, # True on HF Spaces (localhost blocked), False locally
|
| 633 |
show_error=True,
|
| 634 |
prevent_thread_lock=True, # stops Gradio pinging localhost β needed on HF Spaces
|
| 635 |
)
|