ayoubkirouane
commited on
Commit
•
4481b9e
1
Parent(s):
1ae95bf
Upload 2 files
Browse files- app.py +26 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Load model directly
|
2 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
3 |
+
import torch
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
extractor = AutoFeatureExtractor.from_pretrained("ayoubkirouane/VIT_Beans_Leaf_Disease_Classifier")
|
7 |
+
model = AutoModelForImageClassification.from_pretrained("ayoubkirouane/VIT_Beans_Leaf_Disease_Classifier")
|
8 |
+
|
9 |
+
labels = ['angular_leaf_spot', 'bean_rust', 'healthy']
|
10 |
+
|
11 |
+
def classify(im):
|
12 |
+
features = extractor(im, return_tensors='pt')
|
13 |
+
logits = model(features["pixel_values"])[-1]
|
14 |
+
probability = torch.nn.functional.softmax(logits, dim=-1)
|
15 |
+
probs = probability[0].detach().numpy()
|
16 |
+
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
|
17 |
+
return confidences
|
18 |
+
|
19 |
+
interface = gr.Interface(
|
20 |
+
classify,
|
21 |
+
inputs='image',
|
22 |
+
outputs='label',
|
23 |
+
)
|
24 |
+
|
25 |
+
interface.launch(share=True , debug=True)
|
26 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers[torch]
|
2 |
+
Pillow
|