Spaces:
Runtime error
Runtime error
Commit
·
4b2ef4b
1
Parent(s):
e03b0f3
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import load_learner
|
| 3 |
+
from fastai import *
|
| 4 |
+
import torch
|
| 5 |
+
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
model_path = 'multi_target_resnet18.pkl'
|
| 9 |
+
model = load_learner(model_path)
|
| 10 |
+
|
| 11 |
+
def result(path):
|
| 12 |
+
pred,_,probability = model.predict(path)
|
| 13 |
+
arr = ['Name','Status','Disease Name']
|
| 14 |
+
vals = ['', '', '']
|
| 15 |
+
|
| 16 |
+
names = ['Maple', 'Banana', 'Cucumber', 'Mango', 'Maple', 'Pepper', 'Rose', 'Tomato']
|
| 17 |
+
status = ['diseased', 'no disease found']
|
| 18 |
+
|
| 19 |
+
for x in pred:
|
| 20 |
+
if x in names:
|
| 21 |
+
vals[0] = x.capitalize()
|
| 22 |
+
elif x in status:
|
| 23 |
+
vals[1] = x.capitalize()
|
| 24 |
+
elif x == 'healthy':
|
| 25 |
+
vals[2] = 'None'
|
| 26 |
+
else:
|
| 27 |
+
vals[2] = x.capitalize()
|
| 28 |
+
|
| 29 |
+
return f'{arr[0]}:\t{vals[0]}\n{arr[1]}:\t{vals[1]}\n{arr[2]}:\t{vals[2]}\n'
|
| 30 |
+
|
| 31 |
+
path = 'test-images'
|
| 32 |
+
|
| 33 |
+
image_path = []
|
| 34 |
+
|
| 35 |
+
for i in os.listdir(path):
|
| 36 |
+
image_path.append(path+i)
|
| 37 |
+
|
| 38 |
+
image = gr.inputs.Image(shape =(300,300))
|
| 39 |
+
label = gr.outputs.Label()
|
| 40 |
+
|
| 41 |
+
iface = gr.Interface(fn=result, inputs=image, outputs='text', examples = image_path)
|
| 42 |
+
iface.launch(inline = False)
|