Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,18 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
from fastai.basics import *
|
| 4 |
from fastai.vision import models
|
| 5 |
from fastai.vision.all import *
|
| 6 |
from fastai.metrics import *
|
| 7 |
from fastai.data.all import *
|
| 8 |
from fastai.callback import *
|
|
|
|
| 9 |
import PIL
|
| 10 |
import torchvision.transforms as transforms
|
| 11 |
|
|
|
|
|
|
|
| 12 |
from huggingface_hub import hf_hub_download
|
| 13 |
hf_hub_download(repo_id="Alesteba/deep_model_03", filename="unet.pth")
|
| 14 |
|
|
@@ -30,6 +34,8 @@ def transform_image(image):
|
|
| 30 |
|
| 31 |
return my_transforms(image_aux).unsqueeze(0).to(device)
|
| 32 |
|
|
|
|
|
|
|
| 33 |
def predict(img):
|
| 34 |
img = PIL.Image.fromarray(img, "RGB")
|
| 35 |
image = transforms.Resize((480,640))(img)
|
|
@@ -48,21 +54,10 @@ def predict(img):
|
|
| 48 |
mask=np.reshape(mask,(480,640))
|
| 49 |
return Image.fromarray(mask.astype('uint8'))
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# # Definimos una funci贸n que se encarga de llevar a cabo las predicciones
|
| 60 |
-
# def predict(img):
|
| 61 |
-
# #img = PILImage.create(img)
|
| 62 |
-
# pred,pred_idx,probs = learner.predict(img)
|
| 63 |
-
# return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 64 |
-
|
| 65 |
-
# Creamos la interfaz y la lanzamos.
|
| 66 |
-
|
| 67 |
-
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=[gr.outputs.Image(type="pil", label="Predicci贸n")], examples=['color_154.jpg','color_155.jpg']).launch(share=False)
|
| 68 |
|
|
|
|
| 1 |
+
|
| 2 |
import gradio as gr
|
| 3 |
+
|
| 4 |
from fastai.basics import *
|
| 5 |
from fastai.vision import models
|
| 6 |
from fastai.vision.all import *
|
| 7 |
from fastai.metrics import *
|
| 8 |
from fastai.data.all import *
|
| 9 |
from fastai.callback import *
|
| 10 |
+
|
| 11 |
import PIL
|
| 12 |
import torchvision.transforms as transforms
|
| 13 |
|
| 14 |
+
# direct download
|
| 15 |
+
|
| 16 |
from huggingface_hub import hf_hub_download
|
| 17 |
hf_hub_download(repo_id="Alesteba/deep_model_03", filename="unet.pth")
|
| 18 |
|
|
|
|
| 34 |
|
| 35 |
return my_transforms(image_aux).unsqueeze(0).to(device)
|
| 36 |
|
| 37 |
+
# Definimos una funci贸n que se encarga de llevar a cabo las predicciones
|
| 38 |
+
|
| 39 |
def predict(img):
|
| 40 |
img = PIL.Image.fromarray(img, "RGB")
|
| 41 |
image = transforms.Resize((480,640))(img)
|
|
|
|
| 54 |
mask=np.reshape(mask,(480,640))
|
| 55 |
return Image.fromarray(mask.astype('uint8'))
|
| 56 |
|
| 57 |
+
gr.Interface(
|
| 58 |
+
fn=predict,
|
| 59 |
+
inputs=gr.inputs.Image(shape=(128, 128)),
|
| 60 |
+
outputs=[gr.outputs.Image(type="pil", label="Prediction")],
|
| 61 |
+
examples=['color_154.jpg','color_155.jpg']
|
| 62 |
+
).launch(share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|