Spaces:
Runtime error
Runtime error
First model version
Browse files- Plant-disease-detector.ipynb +0 -0
- app.py +44 -0
- export.pkl +3 -0
- requirements.txt +3 -0
Plant-disease-detector.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
#%reload_ext autoreload
|
4 |
+
#%autoreload 2
|
5 |
+
#%matplotlib inline
|
6 |
+
#!pip install fastai --upgrade
|
7 |
+
#!pip install voila
|
8 |
+
#!jupyter serverextension enable --sys-prefix voila
|
9 |
+
#!pip install gradio
|
10 |
+
|
11 |
+
from fastai import *
|
12 |
+
from fastai.vision import *
|
13 |
+
from fastai.vision.all import *
|
14 |
+
from fastai.metrics import error_rate, accuracy
|
15 |
+
from fastai.imports import *
|
16 |
+
import gdown
|
17 |
+
import gradio as gr
|
18 |
+
from gradio.themes.base import Base
|
19 |
+
|
20 |
+
## Export the trained ResNet classifer model
|
21 |
+
path = Path()
|
22 |
+
learn_inf = load_learner(path/'export.pkl')
|
23 |
+
learn_inf.dls.vocab
|
24 |
+
image = gr.Image(shape=(180,180))
|
25 |
+
|
26 |
+
## Define predicting action
|
27 |
+
def predict(img):
|
28 |
+
img = PILImage.create(img)
|
29 |
+
pred,pred_idx,probs = learn_inf.predict(img)
|
30 |
+
return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
|
31 |
+
|
32 |
+
## Define title, description and emoji
|
33 |
+
note_text = '\U00002728' + 'This plant disease detector targets on diagnosing the leaves disease of fruit and vegetables. Upload the leaf picture here! ' + '\U0001FA84'
|
34 |
+
|
35 |
+
## Set Gradio interface
|
36 |
+
gr_interface = gr.Interface(fn=predict, inputs=gr.Image(shape=(180, 180)),outputs=gr.Label(num_top_classes=len(learn_inf.dls.vocab)), interpretation="default",title = '\U0001F31D'+'Plant Disease Detector'+'\U0001FAB4',description = note_text, theme='gradio/seafoam')
|
37 |
+
|
38 |
+
## Use interface launch
|
39 |
+
gr_interface.launch(share=True)
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|
export.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6ddbf0376c62b8d550a826810b8e37d85ebbda1688c6779c984f7c110b1616ff
|
3 |
+
size 90784031
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
fastai==2.7.13
|
2 |
+
gdown==4.5.1
|
3 |
+
gradio==3.50.2
|