import streamlit as st from PIL import Image import torch from model import ModelColorization from utils import process_gs_image, inverse_transform_cs # Custom CSS for styling st.markdown( """ """, unsafe_allow_html=True ) # Load model model = ModelColorization().from_pretrained("sebastiansarasti/AutoEncoderImageColorization") # App header st.markdown('
🎨 Neural Image Colorizer
', unsafe_allow_html=True) st.markdown('Bring black & white photos to life with AI
', unsafe_allow_html=True) # Upload section with st.container(): st.markdown("### 📤 Upload Your Image") uploaded_file = st.file_uploader( "Choose a black & white photo...", type=["jpg", "jpeg", "png"], label_visibility="collapsed" ) # Processing section if uploaded_file is not None: with st.container(): col1, col2 = st.columns(2) with col1: st.markdown("### ⬆ Original") original_img = Image.open(uploaded_file) st.image(original_img, use_container_width=True) with col2: st.markdown("### 🎨 Colorized") if st.button("✨ Colorize Image", type="primary"): with st.spinner("Colorizing your image..."): # Process image image, original_size = process_gs_image(original_img) # Run model model.eval() with torch.no_grad(): result = model(image) # Get colorized image colorized_image = inverse_transform_cs(result.squeeze(0), original_size) # Display result st.image(colorized_image, use_container_width=True) st.success("Colorization complete!") # Footer st.markdown( ' ', unsafe_allow_html=True )