maviced commited on
Commit
933b3a7
·
verified ·
1 Parent(s): da3258a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +26 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import from_pretrained_fastai
2
+ import gradio as gr
3
+ from fastai.vision.all import *
4
+ import os
5
+
6
+ try:
7
+ import toml
8
+ except ImportError:
9
+ os.system('pip install toml')
10
+ import toml
11
+
12
+
13
+ # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"
14
+ repo_id = "maviced/chest_xray"
15
+
16
+ learner = from_pretrained_fastai(repo_id)
17
+ labels = learner.dls.vocab
18
+
19
+ # Definimos una función que se encarga de llevar a cabo las predicciones
20
+ def predict(img):
21
+ # img = PILImage.create(img)
22
+ pred,pred_idx,probs = learner.predict(img)
23
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
24
+
25
+ # Creamos la interfaz y la lanzamos.
26
+ gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Label(num_top_classes=3),examples=['IM-0006-0001.jpeg','person100_bacteria_482.jpeg']).launch(share=False)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ fastai