awacke1 commited on
Commit
097f3b2
·
verified ·
1 Parent(s): 11cacea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Use width and height instead of shape
19
+ image_input = gr.Image(width=128, height=128)
20
+ label_output = gr.Label()
21
+
22
+ # Create submit button
23
+ submit_btn = gr.Button("Classify")
24
+ submit_btn.click(fn=predict, inputs=image_input, outputs=label_output)
25
+
26
+ # Adding examples
27
+ gr.Examples(examples, inputs=image_input, outputs=label_output, fn=predict)
28
+
29
+ demo.launch()