cjensen commited on
Commit
39ca714
1 Parent(s): dbf5760

app, requirements, example images

Browse files
Files changed (6) hide show
  1. app.py +45 -0
  2. image1.jpg +0 -0
  3. image2.jpg +0 -0
  4. image3.jpg +0 -0
  5. image4.jpg +0 -0
  6. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import torch
3
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
4
+
5
+ dataset = datasets.load_dataset('beans')
6
+
7
+ feature_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 = feature_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
+ import gradio as gr
21
+
22
+ Instruction = "Submit bean-leaf images with different leaf conditions"
23
+ title="Bean-leaf-disease Image classification demo"
24
+ description = "Drop an Input image to classify, Observe the model prediction across 3 distinct categories."
25
+ article = """
26
+ - Select an image from the examples provided as demo image
27
+ - Click submit button to make Image classification
28
+ - Click clear button to try new Image for classification
29
+ """
30
+
31
+ interface = gr.Interface(
32
+ classify,
33
+ inputs='image',
34
+ outputs='label',
35
+ instructuction = Instruction,
36
+ title = title,
37
+ description = description,
38
+ article = article,
39
+ examples=["image1.jpg",
40
+ "image2.jpg",
41
+ "image3.jpg",
42
+ "image4.jpg"]
43
+ )
44
+
45
+ interface.launch(debug=True)
image1.jpg ADDED
image2.jpg ADDED
image3.jpg ADDED
image4.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ transformers