-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
69 lines (47 loc) · 1.73 KB
/
app.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
import tensorflow as tf
import tensorflow_hub as hub
import matplotlib.pyplot as plt
import numpy as np
from utils import set_background
set_background("./imgs/background.png")
header = st.container()
body = st.container()
model=''
if model=='':
model = tf.keras.models.load_model(
("./model/avatar_faces_model.h5"),
custom_objects={'KerasLayer':hub.KerasLayer}
)
def generate_avatar_images(model) :
test_input = tf.random.normal([16, 128])
n = 16
n = int(np.sqrt(n))
predictions = model.predict(test_input)
predictions = (predictions + 1) / 2.0
fig = plt.figure(figsize=(6, 6))
for i in range(n * n):
plt.subplot(n, n, i+1)
plt.axis("off")
plt.imshow(predictions[i], cmap="viridis")
return fig
with header :
_, col0, _ = st.columns([0.25,1,0.1])
col0.title("💥 GANs Avatar Face Generator 🤖")
_, col1, _ = st.columns([0.3,1,0.2])
col1.image("./imgs/avatars_gan.gif", width=400)
_, col2, _ = st.columns([0.3,1,0.2])
col2.subheader("Avatar Face Model Generator with TensorFlow 🧪")
_, col3, _ = st.columns([0.3,1,0.1])
col3.image("./imgs/avatars_preview.png", width=370)
st.write("This GANs Model was trained with over 20.000 Images, using TensorFlow and the Google Colab GPU.")
with body :
_, col4, _ = st.columns([0.4,1,0.3])
col4.subheader("Check It-out the GANs Generator Model 🔎!")
_, col5, _ = st.columns([0.65,1,0.2])
if col5.button("Generate Avatar Images"):
avatars = generate_avatar_images(model)
_, col6, _ = st.columns([0.5,1,0.2])
col6.header("Avatar Results ✅:")
_, col7, _ = st.columns([0.1,1,0.1])
col7.pyplot(avatars)