Spaces:
Running on Zero
Running on Zero
Commit ·
7de3058
1
Parent(s): 1ae40eb
fix app.py
Browse files
app.py
CHANGED
|
@@ -16,11 +16,22 @@ import sys
|
|
| 16 |
import tempfile
|
| 17 |
import time
|
| 18 |
from pathlib import Path
|
| 19 |
-
|
| 20 |
try:
|
| 21 |
import spaces
|
| 22 |
except ImportError:
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
import gradio as gr
|
| 25 |
import numpy as np
|
| 26 |
from PIL import Image
|
|
@@ -98,7 +109,6 @@ def load_category_map(checkpoint: str | Path) -> dict[str, int]:
|
|
| 98 |
|
| 99 |
return {}
|
| 100 |
|
| 101 |
-
|
| 102 |
def get_category_name(cat_map: dict[str, int], tag: str) -> str:
|
| 103 |
cat_id = cat_map.get(tag, 0)
|
| 104 |
return CATEGORY_MAP.get(cat_id, "general")
|
|
@@ -377,6 +387,7 @@ def build_app(predict_fn, model_choices: list[str]) -> gr.Blocks:
|
|
| 377 |
csv = ", ".join(format_tag(t, _use_underscore) for t, _ in items)
|
| 378 |
return table, csv
|
| 379 |
|
|
|
|
| 380 |
def on_analyze(image, url):
|
| 381 |
if image is None and not url:
|
| 382 |
return *refresh_results(
|
|
|
|
| 16 |
import tempfile
|
| 17 |
import time
|
| 18 |
from pathlib import Path
|
|
|
|
| 19 |
try:
|
| 20 |
import spaces
|
| 21 |
except ImportError:
|
| 22 |
+
class MockSpaces:
|
| 23 |
+
def GPU(self, func=None, **kwargs):
|
| 24 |
+
if func is not None and callable(func):
|
| 25 |
+
# Used as @spaces.GPU
|
| 26 |
+
return func
|
| 27 |
+
|
| 28 |
+
# Used as @spaces.GPU(...)
|
| 29 |
+
def decorator(f):
|
| 30 |
+
return f
|
| 31 |
+
return decorator
|
| 32 |
+
|
| 33 |
+
spaces = MockSpaces()
|
| 34 |
+
|
| 35 |
import gradio as gr
|
| 36 |
import numpy as np
|
| 37 |
from PIL import Image
|
|
|
|
| 109 |
|
| 110 |
return {}
|
| 111 |
|
|
|
|
| 112 |
def get_category_name(cat_map: dict[str, int], tag: str) -> str:
|
| 113 |
cat_id = cat_map.get(tag, 0)
|
| 114 |
return CATEGORY_MAP.get(cat_id, "general")
|
|
|
|
| 387 |
csv = ", ".join(format_tag(t, _use_underscore) for t, _ in items)
|
| 388 |
return table, csv
|
| 389 |
|
| 390 |
+
@spaces.GPU
|
| 391 |
def on_analyze(image, url):
|
| 392 |
if image is None and not url:
|
| 393 |
return *refresh_results(
|