RKoops commited on
Commit
ee89c9b
·
1 Parent(s): 94ed41b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ labels = dataset["train"].features["labels"].names
8
+
9
+ extractor = AutoFeatureExtractor.from_pretrained("RKoops/BeanLeaf")
10
+ model = AutoModelForImageClassification.from_pretrained("RKoops/BeanLeaf")
11
+
12
+
13
+ def classify(im):
14
+ features = extractor(im, return_tensors="pt")
15
+ logits = model(features["pixel_values"])[-1]
16
+ probability = torch.nn.functional.softmax(logits, dim=-1)
17
+ probs = probability[0].detach().numpy()
18
+ confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
19
+ return confidences
20
+
21
+
22
+ interface = gr.Interface(
23
+ classify,
24
+ inputs="image",
25
+ outputs="label",
26
+ title="Bean plant disease classifier",
27
+ description="Detect diseases in beans using images of leaves",
28
+ )
29
+
30
+ interface.launch()