JuncalG commited on
Commit
a8e9d7c
·
verified ·
1 Parent(s): c879a8d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import from_pretrained_fastai
3
+ from fastai.learner import load_learner
4
+ from PIL import Image
5
+ from fastai.vision.all import load_learner
6
+
7
+
8
+ repo_id = "JuncalG/Practica2"
9
+
10
+ learner = from_pretrained_fastai(repo_id)
11
+ labels = learner.dls.vocab
12
+
13
+
14
+ def predict(img):
15
+ pred, pred_idx, probs = learner.predict(img)
16
+ return {str(learner.dls.vocab[i]): float(probs[i]) for i in range(len(probs))}
17
+
18
+ # Usar componentes nuevos (Gradio moderno)
19
+ demo = gr.Interface(
20
+ fn=predict,
21
+ inputs=gr.Image(type="pil"),
22
+ outputs=gr.Label(num_top_classes=5),
23
+ examples=['af3b0115aad1.png', 'b191ba0a2b12.png']
24
+ )
25
+
26
+
27
+ demo.launch(share=True)