File size: 883 Bytes
95e13a1
 
d167708
616545f
d167708
 
d1a1da3
 
95e13a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from fastai.vision.all import *
import pathlib

plt = platform.system()
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath

learn = load_learner('nihal_model.pkl')
def classify_image(img):
    pred,pred_idx,probs = learn.predict(img)
    #return both the prediction and the probability either nihal or not and format in perccentage
    return pred, "{:.0%}".format(float(probs[pred_idx])),float(probs[~pred_idx])
    #return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'


if __name__ == '__main__':
    # Define inputs and outputs for Gradio interface
    inputs = [gr.Image(type="pil", label="Select an image of Nihal")]
    outputs = [
        gr.Label(""),
        gr.Label(label="Confidence"),
    ]

    # Launch the Gradio interface
    interface = gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs)
    interface.launch()