Spaces:
Sleeping
Sleeping
[feat]: upload files
Browse files- deployment/gradio/app.py +14 -3
- src/infer.py +1 -8
deployment/gradio/app.py
CHANGED
|
@@ -1,11 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from src.infer import inference_pipeline
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# model_path = "checkpoints/ckpt_23_10_2025/best_cat_dog_classifier_model_20251019_122336.pth"
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def classify_image(
|
| 8 |
-
image_path: str
|
| 9 |
) -> str:
|
| 10 |
"""
|
| 11 |
Classify the input image as cat or dog.
|
|
@@ -16,7 +28,6 @@ def classify_image(
|
|
| 16 |
prediction = inference_pipeline(
|
| 17 |
image_path=image_path,
|
| 18 |
model_path=model_path,
|
| 19 |
-
hf=True
|
| 20 |
)
|
| 21 |
return f"Prediction: {prediction.capitalize()}"
|
| 22 |
except Exception as e:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from src.infer import inference_pipeline
|
| 3 |
+
from typing import Optional
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
# model_path = "checkpoints/ckpt_23_10_2025/best_cat_dog_classifier_model_20251019_122336.pth"
|
| 7 |
+
hf = True
|
| 8 |
+
# Load weights
|
| 9 |
+
if hf:
|
| 10 |
+
# Download from Hugging Face Model Hub (not from Spaces)
|
| 11 |
+
model_path = hf_hub_download(
|
| 12 |
+
repo_id="vikenkd/catdog-model",
|
| 13 |
+
filename="best_cat_dog_classifier_model_20251019_122336.pth",
|
| 14 |
+
repo_type="model"
|
| 15 |
+
)
|
| 16 |
+
else:
|
| 17 |
+
model_path = "checkpoints/ckpt_23_10_2025/best_cat_dog_classifier_model_20251019_122336.pth"
|
| 18 |
|
| 19 |
def classify_image(
|
| 20 |
+
image_path: str,
|
| 21 |
) -> str:
|
| 22 |
"""
|
| 23 |
Classify the input image as cat or dog.
|
|
|
|
| 28 |
prediction = inference_pipeline(
|
| 29 |
image_path=image_path,
|
| 30 |
model_path=model_path,
|
|
|
|
| 31 |
)
|
| 32 |
return f"Prediction: {prediction.capitalize()}"
|
| 33 |
except Exception as e:
|
src/infer.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import torch
|
|
|
|
| 2 |
from huggingface_hub import hf_hub_download
|
| 3 |
from src.model import CatDogClassifier
|
| 4 |
from src.config import CatDogClassifierConfigs
|
|
@@ -23,14 +24,6 @@ def inference_pipeline(
|
|
| 23 |
)
|
| 24 |
# Load state_dict
|
| 25 |
model = CatDogClassifier(configs=model_configs)
|
| 26 |
-
# Load weights
|
| 27 |
-
if hf:
|
| 28 |
-
# Download from Hugging Face Model Hub (not from Spaces)
|
| 29 |
-
model_path = hf_hub_download(
|
| 30 |
-
repo_id="vikenkd/catdog-model",
|
| 31 |
-
filename="best_cat_dog_classifier_model_20251019_122336.pth",
|
| 32 |
-
repo_type="model"
|
| 33 |
-
)
|
| 34 |
|
| 35 |
# Load state_dict (both local & remote)
|
| 36 |
state_dict = torch.load(model_path, map_location=model_configs.device)
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from typing import Optional
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
from src.model import CatDogClassifier
|
| 5 |
from src.config import CatDogClassifierConfigs
|
|
|
|
| 24 |
)
|
| 25 |
# Load state_dict
|
| 26 |
model = CatDogClassifier(configs=model_configs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Load state_dict (both local & remote)
|
| 29 |
state_dict = torch.load(model_path, map_location=model_configs.device)
|