File size: 866 Bytes
b778dd5
494fcf3
5b731a2
313dbee
 
f68b432
313dbee
 
f68b432
 
 
 
 
 
313dbee
 
494fcf3
313dbee
f68b432
 
 
 
 
 
 
 
 
4f0f656
421a3c0
b778dd5
f68b432
 
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
import gradio as gr
from fastai.vision.all import *

path = Path()
path.ls(file_exts='.pkl')

# Specify the path to your fastai model file
learn_inf = load_learner(path/'export.pkl')

# Define the predict function
def predict(image):
    # Load the input image
    img = PILImage.create(image)

    # Perform inference using the loaded fastai Learner
    pred, pred_idx, probs = learn_inf.predict(img)

    return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'

# Create Gradio interface
iface = gr.Interface(
    fn=predict,
    inputs=gr.Image(upload_button=True, label="Upload a picture of a dog"),
    outputs="text",
    live=True,
    title="Dog Breed Classifier",
    description="Upload a picture of a dog, and the model will classify it as Labrador, Husky, or Bulldog.",
    examples=["Axel.jpg"])


# Launch the Gradio interface
iface.launch()