Download app.py from Beasto/Mask: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/Beasto/Mask/resolve/main/app.py
- Command line
-
hf download hf://spaces/Beasto/Mask/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Beasto/Mask/resolve/main/app.py
1.02 kB
| import streamlit as st | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| import tensorflow_addons as tfa | |
| import tensorflow as tf | |
| from tensorflow.keras.utils import custom_object_scope | |
| # Define a function to create the InstanceNormalization layer | |
| def create_in(): | |
| return tfa.layers.InstanceNormalization() | |
| def model_out(model_path,img): | |
| with custom_object_scope({'InstanceNormalization': create_in}): | |
| model = tf.keras.models.load_model(model_path) | |
| img = (img-127.5)/127.5 | |
| img = np.expand_dims(img, 0) | |
| pred = model.predict(img) | |
| pred = np.asarray(pred) | |
| return pred[0] | |
| day_inp = st.file_uploader("Sketch input") | |
| if day_inp is not None: | |
| img = Image.open(day_inp) | |
| img = img.resize((256,256)) | |
| img = np.asarray(img) | |
| img = np.reshape(img,(256,256,3)) | |
| pred = model_out('FaceWithMask.h5', img) | |
| st.subheader('Input Image') | |
| st.image(img, caption="Uploaded Image") | |
| st.subheader('Pix2Pix Output') | |
| st.image(((pred + 1) * 127.5).astype(np.uint8), caption="Generated Real Face") |