Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.basics import *
|
2 |
+
from fastai.vision import models
|
3 |
+
from fastai.vision.all import *
|
4 |
+
from fastai.metrics import *
|
5 |
+
from fastai.data.all import *
|
6 |
+
from fastai.callback import *
|
7 |
+
|
8 |
+
|
9 |
+
from pathlib import Path
|
10 |
+
import random
|
11 |
+
|
12 |
+
import gradio as gr
|
13 |
+
|
14 |
+
|
15 |
+
# Cargamos el learner
|
16 |
+
learn = load_learner('unet.pht')
|
17 |
+
|
18 |
+
# Definimos las etiquetas de nuestro modelo
|
19 |
+
labels = learn.dls.vocab
|
20 |
+
|
21 |
+
|
22 |
+
# Definimos una función que se encarga de llevar a cabo las predicciones
|
23 |
+
def predict(img):
|
24 |
+
img = PILImage.create(img)
|
25 |
+
pred,pred_idx,probs = learn.predict(img)
|
26 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
27 |
+
|
28 |
+
# Creamos la interfaz y la lanzamos.
|
29 |
+
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Label(num_top_classes=3),examples=['color_154.jpg','color_155.jpg']).launch(share=False)
|