Spaces:
Sleeping
Sleeping
import streamlit as st | |
from io import BytesIO | |
from PIL import Image | |
# from utils import convert_to_bw, load_colorization_model, colorize_bw_image | |
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 Black & White")) | |
# 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 Black & White": | |
# 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", use_container_width=True) | |
# with col2: | |
# st.image(result_img, caption="Processed Image", use_container_width=True) | |
# # 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" | |
# ) |