File size: 1,065 Bytes
52ab7c9
 
 
 
6aba2ae
52ab7c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import tensorflow as tf
import tensorflow_hub as hub
import numpy as np
from PIL import Image

st.write("Loading model...")
module = hub.load("https://tfhub.dev/google/progan-128/1")
def generate_random_face():
    latent_vector = np.random.normal(size=[1,512]).astype(np.float32)
    image = module.signatures['default'](tf.constant(latent_vector))['default']
    image = np.uint8(image.numpy()[0]*255)
    return Image.fromarray(image)

st.title("Random Face Generator")
st.write("Click the button below to generate a random AI generated face")

if st.button("Generate Random Face"):
    generated_image = generate_random_face()
    st.image(generated_image, caption="Generated Face", use_container_width=True)
    image_array = np.array(generated_image)
    txt_filename = "generated_face.txt"
    np.savetxt(txt_filename,image_array.flatten(), fmt="%d")
    st.download_button("Download Image as TXT", txt_filename, txt_filename, "text/plain")
st.sidebar.write("App Version: 1.0")
st.sidebar.write("Model: ProGAN-128 from Tensorflow Hub")