joros244 commited on
Commit
7c42e35
·
1 Parent(s): 0c36d8b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ import gradio as gr
3
+ import cloudpickle
4
+ import numpy as np
5
+ device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
6
+
7
+
8
+ # Cargamos el learner
9
+ def load(f, map_location='cpu', pickle_module=pickle, **pickle_load_args):
10
+ with open ('modelomemes.pkl',mode='rb') as file:
11
+ learn=cloudpickle.load(file)
12
+
13
+
14
+
15
+
16
+ # Definimos una función que se encarga de llevar a cabo las predicciones
17
+ def predict(img):
18
+ imgLAB = cv2.cvtColor(img.astype('uint8'), cv2.COLOR_BGR2LAB)
19
+ img_pred,a,b = learn.predict(imgLAB[:,:,0])
20
+ arrL = np.array(img_pred)[0,:,:]
21
+ arrA = np.array(img_pred)[1,:,:]
22
+ arrB = np.array(img_pred)[2,:,:]
23
+ imgP = np.stack((arrB,arrA,arrL),axis=2)
24
+ imgColorRGB = cv2.cvtColor(imgP.astype('uint8'), cv2.COLOR_LAB2BGR)
25
+ return(imgColorRGB)
26
+
27
+ # Creamos la interfaz y la lanzamos.
28
+ gr.Interface(fn=predict, inputs=gr.inputs.Image(), outputs=gr.outputs.Image()).launch(share=False)