import gradio as gr from PIL import Image from utils.preprocess import preprocess_image from utils.fill_regions import fill_regions, overlay_boundaries from utils.sharpen import sharpen_image from utils.image_io import save_png, save_bmp ################################################## # MAIN PIPELINE ################################################## def process_image(image): if image is None: return None, None, None, None # Step 2 -> Binary binary = preprocess_image(image) debug = Image.fromarray(binary) debug.save("binary_debug.png") # Fill regions filled = fill_regions(binary) # Keep for future use (currently does nothing) filled = overlay_boundaries( filled, binary ) # No sharpening for now final = sharpen_image(filled) # Save downloadable files png_file = save_png(final) bmp_file = save_bmp(final) return ( Image.fromarray(final), Image.fromarray(binary), png_file, bmp_file ) ################################################## # GRADIO UI ################################################## with gr.Blocks( title="Saree Design AI Agent" ) as demo: gr.Markdown( """ # 🎨 Saree Design AI Agent Upload a Step 2 sketch and generate a colour-filled Step 3 image. Current version generates: ✅ White background ✅ Red filled regions ✅ Downloadable PNG and BMP files """ ) with gr.Row(): input_image = gr.Image( type="numpy", label="Step 2 Image" ) output_image = gr.Image( label="Generated Step 3 Image" ) debug_image = gr.Image( label="Detected Line Mask (debug)" ) with gr.Row(): png_file = gr.File( label="Download PNG" ) bmp_file = gr.File( label="Download BMP" ) generate_btn = gr.Button( "Generate Step 3" ) generate_btn.click( fn=process_image, inputs=input_image, outputs=[ output_image, debug_image, png_file, bmp_file ] ) if __name__ == "__main__": demo.launch()