File size: 816 Bytes
48ec379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from fastai.vision.all import *
import skimage

learn = load_learner('characters.pkl')

labels = learn.dls.vocab
def predict(img):
    pred, pred_idx, probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

title = "Video Game Character Classifier"
examples = ['ellie.jpg', 'arthur.jpg', 'kratos.jpg', 'ellielou.jpg']

# Updated Gradio Interface with new syntax
with gr.Blocks() as demo:
    gr.Markdown("# " + title)
    image_input = gr.Image(shape=(128, 128))
    label_output = gr.Label()
    
    # Create submit button
    submit_btn = gr.Button("Classify")
    submit_btn.click(fn=predict, inputs=image_input, outputs=label_output)

    # Adding examples
    gr.Examples(examples, inputs=image_input, outputs=label_output, fn=predict)

demo.launch()