Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,13 +18,12 @@ def _load_predictor() -> MultiModalPredictor:
|
|
| 18 |
EXTRACT_DIR.mkdir(parents=True, exist_ok=True)
|
| 19 |
with zipfile.ZipFile(ZIP_FILENAME, "r") as zf:
|
| 20 |
zf.extractall(str(EXTRACT_DIR))
|
| 21 |
-
# If the zip contains a single folder, use it; else use EXTRACT_DIR
|
| 22 |
contents = list(EXTRACT_DIR.iterdir())
|
| 23 |
predictor_root = contents[0] if (len(contents) == 1 and contents[0].is_dir()) else EXTRACT_DIR
|
| 24 |
-
return MultiModalPredictor.load(str(predictor_root)
|
| 25 |
|
| 26 |
PREDICTOR = _load_predictor()
|
| 27 |
-
CLASS_LABELS = {i: chr(65+i) for i in range(26)} # 0->A ... 25->Z
|
| 28 |
|
| 29 |
def predict(pil_img: Image.Image):
|
| 30 |
if pil_img is None:
|
|
@@ -32,10 +31,13 @@ def predict(pil_img: Image.Image):
|
|
| 32 |
if pil_img.mode != "RGB":
|
| 33 |
pil_img = pil_img.convert("RGB")
|
| 34 |
processed = pil_img.resize((224, 224))
|
| 35 |
-
|
| 36 |
-
img_path =
|
| 37 |
processed.save(img_path)
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
pretty = {}
|
| 40 |
for col in proba_df.columns:
|
| 41 |
label = f"Letter {CLASS_LABELS[col]}" if isinstance(col, int) and 0 <= col < 26 else str(col)
|
|
@@ -49,7 +51,7 @@ EXAMPLES = [
|
|
| 49 |
["https://www.signingsavvy.com/images/words/alphabet/2/c1.jpg"],
|
| 50 |
]
|
| 51 |
|
| 52 |
-
with gr.Blocks() as demo:
|
| 53 |
gr.Markdown("# Sign Language Recognition (AutoGluon Image)")
|
| 54 |
with gr.Row():
|
| 55 |
with gr.Column():
|
|
|
|
| 18 |
EXTRACT_DIR.mkdir(parents=True, exist_ok=True)
|
| 19 |
with zipfile.ZipFile(ZIP_FILENAME, "r") as zf:
|
| 20 |
zf.extractall(str(EXTRACT_DIR))
|
|
|
|
| 21 |
contents = list(EXTRACT_DIR.iterdir())
|
| 22 |
predictor_root = contents[0] if (len(contents) == 1 and contents[0].is_dir()) else EXTRACT_DIR
|
| 23 |
+
return MultiModalPredictor.load(str(predictor_root)) # ← fixed
|
| 24 |
|
| 25 |
PREDICTOR = _load_predictor()
|
| 26 |
+
CLASS_LABELS = {i: chr(65 + i) for i in range(26)} # 0->A ... 25->Z
|
| 27 |
|
| 28 |
def predict(pil_img: Image.Image):
|
| 29 |
if pil_img is None:
|
|
|
|
| 31 |
if pil_img.mode != "RGB":
|
| 32 |
pil_img = pil_img.convert("RGB")
|
| 33 |
processed = pil_img.resize((224, 224))
|
| 34 |
+
tmpdir = pathlib.Path(tempfile.mkdtemp())
|
| 35 |
+
img_path = tmpdir / "input.png"
|
| 36 |
processed.save(img_path)
|
| 37 |
+
|
| 38 |
+
df = pd.DataFrame({"image": [str(img_path)]})
|
| 39 |
+
proba_df = PREDICTOR.predict_proba(df)
|
| 40 |
+
|
| 41 |
pretty = {}
|
| 42 |
for col in proba_df.columns:
|
| 43 |
label = f"Letter {CLASS_LABELS[col]}" if isinstance(col, int) and 0 <= col < 26 else str(col)
|
|
|
|
| 51 |
["https://www.signingsavvy.com/images/words/alphabet/2/c1.jpg"],
|
| 52 |
]
|
| 53 |
|
| 54 |
+
with gr.Blocks(title="Sign Language Recognition") as demo:
|
| 55 |
gr.Markdown("# Sign Language Recognition (AutoGluon Image)")
|
| 56 |
with gr.Row():
|
| 57 |
with gr.Column():
|