File size: 1,198 Bytes
4578a60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import numpy as np
import cv2 as cv2
from tensorflow import keras
import gradio as gr
import matplotlib.pyplot as plt
import os
model = keras.models.load_model('./model1.h5')

def pipeline(img_path, model= model):
  img = plt.imread(img_path)
  width = 96
  height = 96
  dim = (width, height)
  resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
  resized_gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)
  formato = resized_gray.reshape(96,96,1)
  formato = np.repeat(formato, 3, axis=2)
  formato = np.expand_dims(formato,0)
  puntos = model.predict(formato)
  plt.imshow(resized)
  for i in range(1,31,2):
      plt.plot(puntos[0][i-1], puntos[0][i], 'ro')
  plt.savefig('tran.jpg')
  img =  cv2.imread('tran.jpg')
  img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
  os.remove('tran.jpg')
  plt.clf()
  return img
  
examples=[]
examples.append("./1.png")
examples.append("./2.png")
examples.append("./3.png")
examples.append("./4.png")
examples.append("./5.png")

gr.Interface(
    pipeline,
    inputs=gr.inputs.Image(label="Upload THE FACEEEEOOOO", type="filepath"),
    outputs=gr.outputs.Image(type="numpy"),
    title="point on your uglo face >:(",
    examples=examples
).launch()