import torch from diffusers import StableDiffusionImg2ImgPipeline from PIL import Image import gradio as gr # Load model once device = "cuda" if torch.cuda.is_available() else "cpu" pipe = StableDiffusionImg2ImgPipeline.from_pretrained( "runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16 if device == "cuda" else torch.float32 ).to(device) # Function to process image def edit_image(input_image, prompt, strength, guidance): if input_image is None: return None image = input_image.convert("RGB").resize((512, 512)) result = pipe( prompt=prompt, image=image, strength=strength, guidance_scale=guidance ) return result.images[0] # UI Layout app = gr.Interface( fn=edit_image, inputs=[ gr.Image(type="pil", label="Upload Image"), gr.Textbox(label="Prompt", placeholder="Describe the edit (e.g. futuristic, anime, cinematic lighting)"), gr.Slider(0.1, 1.0, value=0.6, label="Strength (change level)"), gr.Slider(1, 15, value=7.5, label="Guidance Scale") ], outputs=gr.Image(label="Edited Image"), title="AI Image-to-Image Editor", description="Upload an image and describe how you want it edited." ) # Launch app app.launch()
No comments yet. Be the first!
Sign in to leave a comment
Architecture diagrams will be automatically generated when the Project Manager creates tasks for your project.
No page designs yet.
The Design Agent will generate JSX pages automatically after user flows are created.
No user flows yet.
The User Flow Agent will generate per-persona navigation diagrams after SRD updates.
No comments yet. Be the first!