File size: 674 Bytes
1fd68f9
 
 
ac7dc3f
 
 
 
1fd68f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastai.vision.all import *
import gradio as gr

# added custom function from my kaggle to ID cat's first letter as uppercase
def is_cat(x):
    return x[0].isupper()

# Load the model you trained and exported from Kaggle
learn = load_learner("model.pkl")

# Define a prediction function for Gradio
def classify_image(img):
    pred, idx, probs = learn.predict(img)
    return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}

# Create a Gradio interface
interface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label()
)

# Launch the interface when the app runs
if __name__ == "__main__":
    interface.launch()