Spaces:
Sleeping
Sleeping
File size: 1,805 Bytes
1c0922f 0ba222d 45cae33 0ffc750 0ba222d 45cae33 0ba222d ff2246c 0ba222d 45cae33 c50decd 45cae33 0ba222d 45cae33 4124dde 45cae33 4124dde 0ba222d 45cae33 0ba222d 45cae33 |
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 |
import streamlit as st
from io import BytesIO
from PIL import Image
from utils import convert_to_bw, load_colorization_model, colorize_bw_image
import os
os.environ["STREAMLIT_SERVER_HEADLESS"] = "true"
st.set_page_config(page_title="Image Colorizer", layout="centered")
st.title("Convert B&W images to Colored and vice versa")
uploaded_file = st.sidebar.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
if uploaded_file:
# Open and convert the uploaded image to RGB format
image = Image.open(uploaded_file).convert("RGB")
option = st.sidebar.selectbox("Choose an action", ("Convert to Black & White", "Colorize Your B&W images"))
if st.sidebar.button("Process"):
#Convert the uploaded image to black and white
if option == "Convert to Black & White":
result_img = convert_to_bw(image)
#Colorize a black and white image using a pre-trained model
elif option == "Colorize Your B&W images":
with st.spinner("Colorizing..."):
net = load_colorization_model()
result_img = colorize_bw_image(image, net)
# Display both images in columns
col1, col2 = st.columns(2)
with col1:
st.image(image, caption="Original Image")
with col2:
st.image(result_img, caption="Processed Image")
# Create a buffer to store image bytes
buffer = BytesIO()
result_img.save(buffer, format="JPEG")
buffer.seek(0) # Reset cursor to the beginning
#Download Image in Jpeg
st.download_button(
label="Download Output Image",
data=buffer ,#result_img.tobytes()
file_name="output.jpeg",
mime="image/jpeg"
) |