dimasichsanul commited on
Commit
297e4b8
1 Parent(s): 91c9b50

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
3
+
4
+ processor = AutoImageProcessor.from_pretrained("dimasichsanul/jute_pest_classification")
5
+ model = AutoModelForImageClassification.from_pretrained("dimasichsanul/jute_pest_classification")
6
+
7
+ def jute_predict(input_image):
8
+ inputs = processor(input_image, return_tensors='pt')
9
+ output = model(**inputs)
10
+
11
+ labels = ['Beet Armyworm', 'Black Hairy', 'Cutworm', 'Field Cricket',
12
+ 'Jute Aphid', 'Jute Hairy', 'Jute Red Mite', 'Jute Semilooper',
13
+ 'Jute Stem Girdler', 'Jute Stem Weevil', 'Leaf Beetle',
14
+ 'Mealybug', 'Pod Borer', 'Scopula Emissaria', 'Termite',
15
+ 'Termite odontotermes (Rambur)', 'Yellow Mite']
16
+ proba = output.logits.softmax(1)
17
+
18
+ label = labels[proba.argmax(1)]
19
+ value = proba.max().item()
20
+ return {"score":value, "label":label}
21
+
22
+ iface = gr.Interface(fn=jute_predict,
23
+ inputs=gr.Image(label="Select jute pest candidate", type="pil"),
24
+ outputs="json",
25
+ title="Jute Pest Classification",)
26
+ iface.launch()