Spaces:
Sleeping
Sleeping
SalmanHabeeb
commited on
Commit
·
73ded6e
1
Parent(s):
a450f2f
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
import os
|
4 |
+
from fastai.vision.all import load_learner
|
5 |
+
|
6 |
+
with open("list.dat", 'rb') as f:
|
7 |
+
categories = pickle.load(f)
|
8 |
+
|
9 |
+
model = load_learner("model.pkl")
|
10 |
+
|
11 |
+
def predict(img):
|
12 |
+
pred, idx, probs = model.predict(img)
|
13 |
+
dict1 = dict(zip(categories, map(float, preds)))
|
14 |
+
dict1 = dict(sorted(dict1.items(), key=lambda item : item[1]))
|
15 |
+
output = {key:dict1[key] for key in dict1.keys()[-3:]}
|
16 |
+
sum = 0
|
17 |
+
for i in dict1.keys()[-3:]:
|
18 |
+
sum += dict1[i]
|
19 |
+
output.update("Other", 1.0 - sum)
|
20 |
+
return output
|
21 |
+
|
22 |
+
image = gr.inputs.Image(shape=(264, 264))
|
23 |
+
label = gr.outputs.Label()
|
24 |
+
examples = ["cherry_leaf.jpg", "frogeye_spots_apple_leaf.jpg", "apple_leaf.jpg"]
|
25 |
+
examples = [os.path.join("images", example) for example in examples]
|
26 |
+
|
27 |
+
interface = gr.Interface(fn=predict, inputs=image, outputs=label, examples=examples)
|
28 |
+
interface.launch()
|