ArturG9 commited on
Commit
59209f4
·
verified ·
1 Parent(s): afe4e17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -1,17 +1,27 @@
1
 
2
- from gradio.components import Image, Label
 
 
3
  import gradio as gr
4
 
5
- def predict(img):
6
- # Replace this with your actual prediction logic
7
- return "Your image is: " + img.filename
 
 
 
 
 
 
8
 
9
- title = "Minimal Gradio Example"
10
- description = "This example demonstrates using Gradio with an image input and label output."
11
 
12
- gr.Interface(fn=predict,
13
- inputs=Image(), # No shape specified, Gradio will handle different sizes
14
- outputs=Label(),
15
- title=title,
16
- description=description
17
- ).launch()
 
 
 
 
 
1
 
2
+ __all__ = ['learner', 'labels', 'interface', 'classify']
3
+
4
+ from fastai.vision.all import *
5
  import gradio as gr
6
 
7
+ learner = load_learner('ConvNext_RmsProps.pkl')
8
+
9
+ labels = learner.dls.vocab
10
+
11
+
12
+ def classify(img):
13
+ img = PILImage.create(img)
14
+ pred, pred_idx, probs = learner.predict(img)
15
+ return {labels[i]: float(probs[i]) for i in range (len(labels))}
16
 
 
 
17
 
18
+ interface = gr.Interface(
19
+ fn=classify,
20
+ inputs=gr.Image(),
21
+ outputs=gr.Label(),
22
+ examples=['Amanita.jpg'],
23
+ allow_flagging='never',
24
+ title='Bear classifier',
25
+ description='Model trained to classify four types of bears — black, giant panda, red panda and polar.'
26
+ )
27
+ interface.launch(share=False, inline=False)