Fix Space runtime: pin numpy<2, upgrade gradio, return list outputs, bind server & share on Spaces
Browse files- app.py +6 -1
- gradio_two_stage_app.py +3 -3
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
|
|
| 1 |
from gradio_two_stage_app import build_interface
|
| 2 |
|
| 3 |
if __name__ == "__main__":
|
| 4 |
demo = build_interface()
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
from gradio_two_stage_app import build_interface
|
| 3 |
|
| 4 |
if __name__ == "__main__":
|
| 5 |
demo = build_interface()
|
| 6 |
+
# On Spaces, localhost may not be accessible; serve on 0.0.0.0 and enable share
|
| 7 |
+
if os.environ.get("SPACE_ID"):
|
| 8 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), share=True)
|
| 9 |
+
else:
|
| 10 |
+
demo.launch()
|
gradio_two_stage_app.py
CHANGED
|
@@ -45,7 +45,7 @@ def _as_table_rows(labels, probs):
|
|
| 45 |
|
| 46 |
def predict(image: Image.Image):
|
| 47 |
if image is None:
|
| 48 |
-
return gr.update(value="No image provided."),
|
| 49 |
try:
|
| 50 |
cascade = get_cascade()
|
| 51 |
tmp_path = '___temp_input.png'
|
|
@@ -53,7 +53,7 @@ def predict(image: Image.Image):
|
|
| 53 |
result = cascade.predict(tmp_path)
|
| 54 |
os.remove(tmp_path)
|
| 55 |
except Exception as e:
|
| 56 |
-
return f"Error during inference: {e}",
|
| 57 |
|
| 58 |
binary_part = result.get('binary', {})
|
| 59 |
multi_part = result.get('multiclass', {})
|
|
@@ -77,7 +77,7 @@ def predict(image: Image.Image):
|
|
| 77 |
bin_probs = binary_part.get('probs', []) or []
|
| 78 |
bin_rows = _as_table_rows(getattr(get_cascade(), 'bin_id2label', {}), bin_probs)
|
| 79 |
|
| 80 |
-
multi_rows =
|
| 81 |
if 'multiclass' in result:
|
| 82 |
m_probs = multi_part.get('probs', []) or []
|
| 83 |
multi_rows = _as_table_rows(getattr(get_cascade(), 'multi_id2label', {}), m_probs)
|
|
|
|
| 45 |
|
| 46 |
def predict(image: Image.Image):
|
| 47 |
if image is None:
|
| 48 |
+
return gr.update(value="No image provided."), [], []
|
| 49 |
try:
|
| 50 |
cascade = get_cascade()
|
| 51 |
tmp_path = '___temp_input.png'
|
|
|
|
| 53 |
result = cascade.predict(tmp_path)
|
| 54 |
os.remove(tmp_path)
|
| 55 |
except Exception as e:
|
| 56 |
+
return f"Error during inference: {e}", [], []
|
| 57 |
|
| 58 |
binary_part = result.get('binary', {})
|
| 59 |
multi_part = result.get('multiclass', {})
|
|
|
|
| 77 |
bin_probs = binary_part.get('probs', []) or []
|
| 78 |
bin_rows = _as_table_rows(getattr(get_cascade(), 'bin_id2label', {}), bin_probs)
|
| 79 |
|
| 80 |
+
multi_rows = []
|
| 81 |
if 'multiclass' in result:
|
| 82 |
m_probs = multi_part.get('probs', []) or []
|
| 83 |
multi_rows = _as_table_rows(getattr(get_cascade(), 'multi_id2label', {}), m_probs)
|
requirements.txt
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
-
gradio==4.44.
|
| 2 |
transformers==4.44.2
|
| 3 |
huggingface_hub==0.24.5
|
| 4 |
torch==2.2.1
|
| 5 |
torchvision==0.17.1
|
| 6 |
safetensors==0.4.3
|
| 7 |
Pillow==10.3.0
|
|
|
|
|
|
| 1 |
+
gradio==4.44.1
|
| 2 |
transformers==4.44.2
|
| 3 |
huggingface_hub==0.24.5
|
| 4 |
torch==2.2.1
|
| 5 |
torchvision==0.17.1
|
| 6 |
safetensors==0.4.3
|
| 7 |
Pillow==10.3.0
|
| 8 |
+
numpy<2
|