Spaces:
Sleeping
Sleeping
[feat]: upload files
Browse files- README.md +10 -27
- deployment/gradio/__init__.py +0 -0
- deployment/gradio/app.py +41 -0
README.md
CHANGED
|
@@ -1,27 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
- Other Requirements:
|
| 12 |
-
- GPU (E.g: NVIDIA RTX 3050,...)
|
| 13 |
-
- Python version >= 3.9
|
| 14 |
-
|
| 15 |
-
## How to run this project:
|
| 16 |
-
### Training the model:
|
| 17 |
-
- Utilizing `python src/train.py`
|
| 18 |
-
|
| 19 |
-
### Run Deployment on your local:
|
| 20 |
-
- Utilizing `python deployment/gradio/main.py` \
|
| 21 |
-
Or
|
| 22 |
-
- On HuggingFace Server, you can access at: ``
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Image Classification - Cat & Dog Classification
|
| 3 |
+
emoji: 🐶🐱
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "4.44.0"
|
| 8 |
+
app_file: deployment/gradio/app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deployment/gradio/__init__.py
ADDED
|
File without changes
|
deployment/gradio/app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.
|
| 12 |
+
"""
|
| 13 |
+
if image_path is None:
|
| 14 |
+
return "Please upload an image."
|
| 15 |
+
try:
|
| 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:
|
| 23 |
+
return f"Error: {str(e)}"
|
| 24 |
+
|
| 25 |
+
with gr.Blocks() as demo:
|
| 26 |
+
gr.Markdown("# 🐶🐱 Cat vs Dog Classifier")
|
| 27 |
+
|
| 28 |
+
with gr.Row():
|
| 29 |
+
with gr.Column():
|
| 30 |
+
image_input = gr.Image(
|
| 31 |
+
type="filepath",
|
| 32 |
+
label="Input"
|
| 33 |
+
)
|
| 34 |
+
classify_button = gr.Button("🔍 Classify")
|
| 35 |
+
with gr.Column():
|
| 36 |
+
output_text = gr.Textbox(label="🧠 Prediction", placeholder="Result will appear here")
|
| 37 |
+
|
| 38 |
+
classify_button.click(fn=classify_image, inputs=[image_input], outputs=[output_text])
|
| 39 |
+
|
| 40 |
+
demo.launch(debug=True)
|
| 41 |
+
|