Spaces:
Running
Running
Patrick Daniel
commited on
Commit
·
ff45b18
1
Parent(s):
8de2cc2
Handle secrets
Browse files
app.py
CHANGED
|
@@ -4,15 +4,20 @@ from PIL import Image
|
|
| 4 |
from transformers import ViTForImageClassification, ViTImageProcessor
|
| 5 |
import requests
|
| 6 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load model and processor from Hugging Face Hub
|
| 9 |
-
model = ViTForImageClassification.from_pretrained("patcdaniel/phytoViT_508k_20250611")
|
| 10 |
-
processor = ViTImageProcessor.from_pretrained("patcdaniel/phytoViT_508k_20250611")
|
| 11 |
model.eval()
|
| 12 |
|
| 13 |
# Load class labels from hosted file
|
| 14 |
LABELS_URL = "https://huggingface.co/patcdaniel/phytoViT_508k_20250611/resolve/main/label_names.json"
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
def predict(image):
|
| 18 |
image = image.convert("RGB")
|
|
|
|
| 4 |
from transformers import ViTForImageClassification, ViTImageProcessor
|
| 5 |
import requests
|
| 6 |
import json
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 10 |
+
|
| 11 |
|
| 12 |
# Load model and processor from Hugging Face Hub
|
| 13 |
+
model = ViTForImageClassification.from_pretrained("patcdaniel/phytoViT_508k_20250611",token=hf_token)
|
| 14 |
+
processor = ViTImageProcessor.from_pretrained("patcdaniel/phytoViT_508k_20250611",token=hf_token)
|
| 15 |
model.eval()
|
| 16 |
|
| 17 |
# Load class labels from hosted file
|
| 18 |
LABELS_URL = "https://huggingface.co/patcdaniel/phytoViT_508k_20250611/resolve/main/label_names.json"
|
| 19 |
+
headers = {"Authorization": f"Bearer {hf_token}"}
|
| 20 |
+
class_labels = requests.get(LABELS_URL, headers=headers).json()
|
| 21 |
|
| 22 |
def predict(image):
|
| 23 |
image = image.convert("RGB")
|