Spaces:
Running
Running
| import torch | |
| from diffusers import DiffusionPipeline | |
| import gradio as gr | |
| # Load the Stable Diffusion model | |
| model_id = "runwayml/stable-diffusion-v1-5" | |
| pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) | |
| pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") | |
| # Define the image generation function | |
| def generate_image(prompt): | |
| if not prompt or prompt.strip() == "": | |
| return "Please enter a prompt." | |
| image = pipe(prompt, guidance_scale=7.5).images[0] | |
| return image | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=generate_image, | |
| inputs=gr.Textbox(label="Enter your prompt", placeholder="e.g. Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"), | |
| outputs=gr.Image(label="Generated Image"), | |
| title="AI Image Generator", | |
| description="Generate stunning AI art using Stable Diffusion v1.5" | |
| ) | |
| # Run the app | |
| if __name__ == "__main__": | |
| interface.launch() | |