lucasdmpp commited on
Commit
a0d83ee
1 Parent(s): 403cb3e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
3
+ import torch
4
+
5
+ dataset = load_dataset('beans')
6
+
7
+ extractor = AutoFeatureExtractor.from_pretrained("lucasdmpp/BeanLeaf")
8
+ model = AutoModelForImageClassification.from_pretrained("lucasdmpp/BeanLeaf")
9
+
10
+ labels = dataset['train'].features['labels'].names
11
+ example_imgs = ["example_0.jpg", "example_1.jpg"]
12
+
13
+ def classify(im):
14
+ features = feature_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
+ import gradio as gr
22
+
23
+ interface = interface = gr.Interface(classify, inputs='image',
24
+ outputs='label',
25
+ title='Bean Classification',
26
+ description='Check the health of your bean leaves',
27
+ examples = example_imgs)
28
+
29
+ interface.launch(debug=True)