salaz055 commited on
Commit
8d36d7f
·
1 Parent(s): 7f0b305

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 gradio
4
+
5
+ dataset = datasets.load_dataset('beans')
6
+
7
+ extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
8
+ model = AutoModelForImageClassification.from_pretrained("saved_model_files")
9
+
10
+ labels = dataset['train'].features['labels'].names
11
+
12
+ def classify(im):
13
+ features = extractor(im, return_tensors='pt')
14
+ logits = model(features["pixel_values"])[-1]
15
+ probability = torch.nn.functional.softmax(logits, dim=-1)
16
+ probs = probability[0].detach().numpy()
17
+ confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
18
+ return confidences
19
+
20
+ interface = gr.Interface(
21
+ fn= classify,
22
+ inputs= "image",
23
+ outputs= "label",
24
+ title = 'Leaf Classication',
25
+ description = "Many farming businesses are turning machine learning to monitor their crops automatically with great accuracy. This application can be used to detect Angular Leaf Spot and Bean Rust!" ,
26
+ #examples = [["/content/4702250d-2b9b-4dc6-b991-552d03ecedc4.png"] , ["/content/collard-greens-contain-many-nutrients.jpg"]]
27
+ )
28
+
29
+ interface.launch()