awacke1 commited on
Commit
48ec379
·
verified ·
1 Parent(s): 1897d0e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ import skimage
4
+
5
+ learn = load_learner('characters.pkl')
6
+
7
+ labels = learn.dls.vocab
8
+ def predict(img):
9
+ pred, pred_idx, probs = learn.predict(img)
10
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
11
+
12
+ title = "Video Game Character Classifier"
13
+ examples = ['ellie.jpg', 'arthur.jpg', 'kratos.jpg', 'ellielou.jpg']
14
+
15
+ # Updated Gradio Interface with new syntax
16
+ with gr.Blocks() as demo:
17
+ gr.Markdown("# " + title)
18
+ image_input = gr.Image(shape=(128, 128))
19
+ label_output = gr.Label()
20
+
21
+ # Create submit button
22
+ submit_btn = gr.Button("Classify")
23
+ submit_btn.click(fn=predict, inputs=image_input, outputs=label_output)
24
+
25
+ # Adding examples
26
+ gr.Examples(examples, inputs=image_input, outputs=label_output, fn=predict)
27
+
28
+ demo.launch()