Upload folder using huggingface_hub
Browse files- app.py +38 -5
- requirements.txt +4 -1
app.py
CHANGED
|
@@ -16,6 +16,32 @@ import gradio as gr
|
|
| 16 |
import matplotlib.pyplot as plt
|
| 17 |
from matplotlib.patches import Polygon
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
try:
|
| 20 |
from src.data_collection import DataCollectionManager, classify_from_percentages_simple
|
| 21 |
except ImportError:
|
|
@@ -1007,8 +1033,15 @@ if __name__ == "__main__":
|
|
| 1007 |
attention_reduction=args.attention_reduction,
|
| 1008 |
task_attention=args.task_attention,
|
| 1009 |
)
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
import matplotlib.pyplot as plt
|
| 17 |
from matplotlib.patches import Polygon
|
| 18 |
|
| 19 |
+
|
| 20 |
+
def _patch_gradio_schema_bool_bug() -> None:
|
| 21 |
+
"""
|
| 22 |
+
Work around Gradio/gradio_client schema parsing bug where boolean schema
|
| 23 |
+
values can crash API info generation.
|
| 24 |
+
"""
|
| 25 |
+
try:
|
| 26 |
+
import gradio_client.utils as gc_utils # type: ignore
|
| 27 |
+
except Exception:
|
| 28 |
+
return
|
| 29 |
+
|
| 30 |
+
if getattr(gc_utils.get_type, "__name__", "") == "_safe_get_type":
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
original_get_type = gc_utils.get_type
|
| 34 |
+
|
| 35 |
+
def _safe_get_type(schema):
|
| 36 |
+
if isinstance(schema, bool):
|
| 37 |
+
return "boolean"
|
| 38 |
+
return original_get_type(schema)
|
| 39 |
+
|
| 40 |
+
gc_utils.get_type = _safe_get_type
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
_patch_gradio_schema_bool_bug()
|
| 44 |
+
|
| 45 |
try:
|
| 46 |
from src.data_collection import DataCollectionManager, classify_from_percentages_simple
|
| 47 |
except ImportError:
|
|
|
|
| 1033 |
attention_reduction=args.attention_reduction,
|
| 1034 |
task_attention=args.task_attention,
|
| 1035 |
)
|
| 1036 |
+
is_space_runtime = bool(os.getenv("SPACE_ID") or os.getenv("HF_SPACE_ID"))
|
| 1037 |
+
launch_kwargs = {
|
| 1038 |
+
"server_name": args.server_name,
|
| 1039 |
+
"server_port": args.server_port,
|
| 1040 |
+
"share": args.share,
|
| 1041 |
+
}
|
| 1042 |
+
if is_space_runtime:
|
| 1043 |
+
# Space does not need public-share tunnel and this avoids extra startup issues.
|
| 1044 |
+
launch_kwargs["share"] = False
|
| 1045 |
+
launch_kwargs["show_api"] = False
|
| 1046 |
+
|
| 1047 |
+
demo.launch(**launch_kwargs)
|
requirements.txt
CHANGED
|
@@ -12,7 +12,10 @@ opencv-python-headless>=4.8.0
|
|
| 12 |
matplotlib>=3.7.0
|
| 13 |
|
| 14 |
# WebUI - Required for Gradio interface
|
| 15 |
-
gradio==4.44.
|
| 16 |
|
| 17 |
# Hub sync/export (Space -> Dataset)
|
| 18 |
huggingface_hub>=0.26.0,<1.0.0
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
matplotlib>=3.7.0
|
| 13 |
|
| 14 |
# WebUI - Required for Gradio interface
|
| 15 |
+
gradio==4.44.1
|
| 16 |
|
| 17 |
# Hub sync/export (Space -> Dataset)
|
| 18 |
huggingface_hub>=0.26.0,<1.0.0
|
| 19 |
+
|
| 20 |
+
# Keep schema generation compatible with Gradio 4.x in Space runtime
|
| 21 |
+
pydantic==2.10.6
|