Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
5 |
+
|
6 |
+
dataset = datasets.load_dataset('beans')
|
7 |
+
|
8 |
+
extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
|
9 |
+
|
10 |
+
model = AutoModelForImageClassification.from_pretrained("saved_model_files")
|
11 |
+
|
12 |
+
labels = dataset['train'].features['labels'].names
|
13 |
+
|
14 |
+
def classify(im):
|
15 |
+
features = extractor(im, return_tensors='pt')
|
16 |
+
logits = model(features["pixel_values"])[-1]
|
17 |
+
probability = torch.nn.functional.softmax(logits, dim=-1)
|
18 |
+
probs = probability[0].detach().numpy()
|
19 |
+
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
|
20 |
+
return confidences
|
21 |
+
|
22 |
+
|
23 |
+
interface = gr.Interface(classify, inputs='image', outputs='label', title='Bean plant disease classifier',description='Detect diseases in beans using images of leaves')
|
24 |
+
|
25 |
+
interface.launch()
|