Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,3 @@
|
|
| 1 |
-
"""
|
| 2 |
-
πΏ Weed Species Classifier β Hugging Face Spaces App
|
| 3 |
-
=====================================================
|
| 4 |
-
Deploy this to a Hugging Face Space (Gradio SDK).
|
| 5 |
-
|
| 6 |
-
Steps:
|
| 7 |
-
1. Create a new Space at https://huggingface.co/spaces
|
| 8 |
-
- Owner: your username
|
| 9 |
-
- Space SDK: Gradio
|
| 10 |
-
- Visibility: Public (free)
|
| 11 |
-
2. Upload this app.py and requirements.txt
|
| 12 |
-
3. Set the HF_MODEL_REPO secret in Space Settings β Variables
|
| 13 |
-
(or just hardcode your repo ID below)
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
import os
|
| 17 |
import json
|
| 18 |
import torch
|
|
@@ -23,16 +8,13 @@ from PIL import Image
|
|
| 23 |
from torchvision import transforms
|
| 24 |
from huggingface_hub import hf_hub_download
|
| 25 |
|
| 26 |
-
# ββ Config ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 27 |
-
# Set this to your model repo, e.g. "your-username/weed-classifier"
|
| 28 |
MODEL_REPO = os.environ.get("HF_MODEL_REPO", "your-username/weed-classifier")
|
| 29 |
|
| 30 |
-
# ββ Load model + class names ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 31 |
print(f"Loading model from {MODEL_REPO}...")
|
| 32 |
|
| 33 |
class_names_path = hf_hub_download(repo_id=MODEL_REPO, filename="class_names.json")
|
| 34 |
with open(class_names_path) as f:
|
| 35 |
-
|
| 36 |
raw = json.load(f)
|
| 37 |
idx_to_species = {int(k): v for k, v in raw.items()}
|
| 38 |
|
|
@@ -90,7 +72,6 @@ or crop, and tell you which species it is.
|
|
| 90 |
"""
|
| 91 |
|
| 92 |
EXAMPLES = [
|
| 93 |
-
# Add paths to example images here if you include them in your Space repo
|
| 94 |
# ["examples/chinee_apple.jpg"],
|
| 95 |
# ["examples/snakeweed.jpg"],
|
| 96 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
import torch
|
|
|
|
| 8 |
from torchvision import transforms
|
| 9 |
from huggingface_hub import hf_hub_download
|
| 10 |
|
|
|
|
|
|
|
| 11 |
MODEL_REPO = os.environ.get("HF_MODEL_REPO", "your-username/weed-classifier")
|
| 12 |
|
|
|
|
| 13 |
print(f"Loading model from {MODEL_REPO}...")
|
| 14 |
|
| 15 |
class_names_path = hf_hub_download(repo_id=MODEL_REPO, filename="class_names.json")
|
| 16 |
with open(class_names_path) as f:
|
| 17 |
+
|
| 18 |
raw = json.load(f)
|
| 19 |
idx_to_species = {int(k): v for k, v in raw.items()}
|
| 20 |
|
|
|
|
| 72 |
"""
|
| 73 |
|
| 74 |
EXAMPLES = [
|
|
|
|
| 75 |
# ["examples/chinee_apple.jpg"],
|
| 76 |
# ["examples/snakeweed.jpg"],
|
| 77 |
]
|