Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from diffusers import StableDiffusionPipeline | |
| import torch | |
| # Load the model (make sure your Hugging Face token is configured if running locally) | |
| pipe = StableDiffusionPipeline.from_pretrained( | |
| "runwayml/stable-diffusion-v1-5", | |
| torch_dtype=torch.float16, | |
| ).to("cuda" if torch.cuda.is_available() else "cpu") | |
| def generate_image(prompt): | |
| image = pipe(prompt).images[0] | |
| return image | |
| # Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## AI Image Generator") | |
| prompt = gr.Textbox(label="Enter your prompt") | |
| btn = gr.Button("Generate Image") | |
| output = gr.Image() | |
| btn.click(fn=generate_image, inputs=prompt, outputs=output) | |
| if __name__ == "__main__": | |
| demo.launch() |