dassum commited on
Commit
26ae28f
1 Parent(s): 21ea66a

leaf disease classification

Browse files
Files changed (2) hide show
  1. app.py +29 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import datasets
3
+ import torch
4
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
5
+
6
+ dataset = datasets.load_dataset('beans') # This should be the same as the first line of Python code in this Colab notebook
7
+
8
+ feature_extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
9
+ model = AutoModelForImageClassification.from_pretrained("saved_model_files")
10
+
11
+ labels = dataset['train'].features['labels'].names
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 = gr.Interface(
24
+ classify,
25
+ inputs='image',
26
+ outputs='label',
27
+ )
28
+
29
+ interface.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ transformers