brxerq commited on
Commit
247143e
·
verified ·
1 Parent(s): 4dde571

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ __all__ = ['bird', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
4
+
5
+ # Load categories from label.txt
6
+ with open('labels.txt', 'r') as file:
7
+ categories = [line.strip() for line in file.readlines()]
8
+
9
+ # Load the model
10
+ from fastai.vision.all import *
11
+ import gradio as gr
12
+
13
+ learn = load_learner('model.pkl')
14
+
15
+ # Define the classification function
16
+ def classify_image(img):
17
+ preds, idx, probs = learn.predict(img)
18
+ return dict(zip(categories, map(float, probs)))
19
+
20
+ # Gradio components
21
+ image = gr.components.Image()
22
+ label = gr.components.Label(num_top_classes=3)
23
+
24
+ # Create and launch the interface
25
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
26
+ intf.launch(inline=False, share=True)