CoolFace
Apppublic

Essa20001/colore

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
app.py36 linesDownload Raw Back to root
1import streamlit as st2import tensorflow as tf3import numpy as np4from PIL import Image5from io import BytesIO6 7st.title("Colorize black and white image using an AI model trained on Flickr images with the Pix2pix architecture.")8image = st.file_uploader("Upload an image", type=["jpg", "png","jpeg"])9model = tf.keras.models.load_model('generator_color.keras')10 11if image :12  button = st.button("Colore")13  image = Image.open(image)14  image = image.convert("L")15  image = image.resize((128,128))16  image = np.array(image)17  if button:18    image = image - 127.519    image = image / 127.520    image.shape = (1,128,128,1)21 22    result = model(image,training = True)23    result = (result * 127.5) + 127.524    numpy_array = np.array(result.numpy()[0] , dtype=np.uint8)25    pillow_image = Image.fromarray(numpy_array)26    output_path = "output_image.jpg"27    pillow_image.save(output_path)28    st.image([output_path], caption='Colored Image', use_column_width=False)29    st.download_button(30            label="Download Colored Image",31            data=BytesIO(numpy_array.tobytes()),32            file_name="output_image.jpg",33            key="download_button",34            help="Click to download the colored image.",35        )36