Spaces:
Running
Running
File size: 2,013 Bytes
47c60f9 |
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 |
# App code based on:
# Model based on:
import numpy as np
import pandas as pd
import streamlit as st
import os
from datetime import datetime
from PIL import Image
from streamlit_drawable_canvas import st_canvas
from io import BytesIO
from copy import deepcopy
from src.core import process_inpaint
st.title("AI Photo Colorization")
st.image(open("assets/demo.png", "rb").read())
st.markdown(
"""
Colorizing black & white photo can be expensive and time consuming. We introduce AI that can colorize
grayscale photo in seconds. **Just upload your grayscale image, then click colorize.**
"""
)
uploaded_file = st.file_uploader("Choose image", accept_multiple_files=False, type=["png", "jpg", "jpeg"])
if uploaded_file is not None:
bytes_data = uploaded_file.getvalue()
img_input = Image.open(BytesIO(bytes_data)).convert("RGBA")
if uploaded_file is not None and st.button("Colorize!"):
with st.spinner("AI is doing the magic!"):
img_output = """TODO"""
# NOTE: Calm! I'm not logging the input and outputs.
# It is impossible to access the filesystem in spaces environment.
now = datetime.now().strftime("%Y%m%d-%H%M%S-%f")
img_input.convert("RGB").save(f"./output/{now}.jpg")
Image.fromarray(img_output).convert("RGB").save(f"./output/{now}-edited.jpg")
st.write("AI has finished the job!")
st.image(img_output)
# reuse = st.button('Edit again (Re-use this image)', on_click=set_image, args=(inpainted_img, ))
with open(f"./output/{now}-edited.jpg", "rb") as fs:
uploaded_name = os.path.splitext(uploaded_file.name)[0]
st.download_button(
label="Download",
data=fs,
file_name=f'edited_{uploaded_name}.jpg',
)
st.info("**TIP**: If the result is not perfect, you can download then "
"re-upload the result then remove the artifacts.")
|