File size: 1,830 Bytes
4abf419
357257b
82abee9
357257b
82abee9
 
357257b
4abf419
 
357257b
4abf419
 
357257b
 
73ded6e
 
 
 
 
 
 
 
 
 
 
 
16f509e
73ded6e
5495328
73ded6e
3dac242
73ded6e
dcb5199
73ded6e
 
b739ca5
 
 
 
556be06
6e38247
73ded6e
b739ca5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# # # Copyright ©️ 2022 Syed Salman Habeeb Quadri 
  
# # # This file is part of Blatt. 
  

# # # Blatt is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 
  

# # # Blatt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 
  

# # # You should have received a copy of the GNU General Public License along with Blatt. If not, see <https://www.gnu.org/licenses/>.


import gradio as gr
import pickle
import os
from fastai.vision.all import load_learner

with open("list.dat", 'rb') as f:
    categories = pickle.load(f)
    
model = load_learner("model.pkl")

def predict(img):
    pred, idx, probs = model.predict(img)
    dict1 = dict(zip(categories, map(float, probs)))
    dict1 = dict(sorted(dict1.items(), key=lambda item : item[1]))
    output = {key:dict1[key] for key in list(dict1.keys())[-3:]}
    sum = 0
    for i in list(dict1.keys())[-3:]:
        sum += dict1[i]
    output.update({"Other" : 1.0 - sum})
    return output


image = gr.inputs.Image(shape=(200, 200))
label = gr.outputs.Label()
text = "<a color='#00FF00'>Keep the background dark and uniform for best results<a>"
examples = ["Potato_late_blight.jpg", "apple_black_rot.jpg", "apple_leaf.jpg"]
examples = [os.path.join("images", example) for example in examples]

interface = gr.Interface(fn=predict, inputs=image, outputs=label, examples=examples, description=text)
interface.launch()