devdata commited on
Commit
d13656f
·
1 Parent(s): cc7a05d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ import skimage
4
+
5
+ learn = load_learner('model.pkl')
6
+
7
+ # Original labels from the model
8
+ labels = learn.dls.vocab
9
+
10
+ # Custom mapping for labels
11
+ custom_labels = {
12
+ "Other": "Nimeshindwa kutambua picha",
13
+ "lateblt": "Ukungu wa mwisho wa viazi",
14
+ "earlyblt": "Ukungu wa mwanzo wa viazi",
15
+ "healthy": "Jani halina ugonjwa"
16
+ }
17
+
18
+ def predict(img):
19
+ img = PILImage.create(img)
20
+ pred, pred_idx, probs = learn.predict(img)
21
+ # Map the model's labels to the custom labels
22
+ return {custom_labels[labels[i]]: float(probs[i]) for i in range(len(labels))}
23
+
24
+ # Other parameters
25
+ examples = ['image.jpg']
26
+ interpretation = 'default'
27
+ enable_queue = True
28
+
29
+ # Launch Gradio interface
30
+ gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3), examples=examples, interpretation=interpretation, enable_queue=enable_queue).launch()