Create new file
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import cv2 as cv2
|
| 3 |
+
from tensorflow import keras
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
import os
|
| 7 |
+
model = keras.models.load_model('./model1.h5')
|
| 8 |
+
|
| 9 |
+
def pipeline(img_path, model= model):
|
| 10 |
+
img = plt.imread(img_path)
|
| 11 |
+
width = 96
|
| 12 |
+
height = 96
|
| 13 |
+
dim = (width, height)
|
| 14 |
+
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
|
| 15 |
+
resized_gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)
|
| 16 |
+
formato = resized_gray.reshape(96,96,1)
|
| 17 |
+
formato = np.repeat(formato, 3, axis=2)
|
| 18 |
+
formato = np.expand_dims(formato,0)
|
| 19 |
+
puntos = model.predict(formato)
|
| 20 |
+
plt.imshow(resized)
|
| 21 |
+
for i in range(1,31,2):
|
| 22 |
+
plt.plot(puntos[0][i-1], puntos[0][i], 'ro')
|
| 23 |
+
plt.savefig('tran.jpg')
|
| 24 |
+
img = cv2.imread('tran.jpg')
|
| 25 |
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
| 26 |
+
os.remove('tran.jpg')
|
| 27 |
+
plt.clf()
|
| 28 |
+
return img
|
| 29 |
+
|
| 30 |
+
examples=[]
|
| 31 |
+
examples.append("./1.png")
|
| 32 |
+
examples.append("./2.png")
|
| 33 |
+
examples.append("./3.png")
|
| 34 |
+
examples.append("./4.png")
|
| 35 |
+
examples.append("./5.png")
|
| 36 |
+
|
| 37 |
+
gr.Interface(
|
| 38 |
+
pipeline,
|
| 39 |
+
inputs=gr.inputs.Image(label="Upload THE FACEEEEOOOO", type="filepath"),
|
| 40 |
+
outputs=gr.outputs.Image(type="numpy"),
|
| 41 |
+
title="point on your uglo face >:(",
|
| 42 |
+
examples=examples
|
| 43 |
+
).launch()
|