Umang-Bansal commited on
Commit
e8a63a2
·
verified ·
1 Parent(s): dc04b43

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 load_learner, PILImage
3
+
4
+ # Load the model
5
+ model_path = "anime.pkl"
6
+ learn = load_learner(model_path)
7
+
8
+ # Define categories
9
+ categories = dls.vocab
10
+
11
+ # Define the image classification function
12
+ def Classify_image(img):
13
+ pred,idx,probs = learn.predict(img)
14
+ return dict(zip(categories, map(float, probs)))
15
+
16
+ # Define the Gradio interface with Blocks
17
+ with gr.Blocks() as demo:
18
+ gr.Markdown("# Anime-character Classifier")
19
+
20
+ with gr.Row():
21
+ with gr.Column():
22
+ image_input = gr.Image()
23
+ classify_button = gr.Button("Classify")
24
+ with gr.Column():
25
+ output_label = gr.Label(label="Classification Result")
26
+
27
+ classify_button.click(Classify_image, inputs=image_input, outputs=output_label)
28
+
29
+ demo.launch()