Sanjayraju30 commited on
Commit
68924be
·
verified ·
1 Parent(s): e7be866

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -25
app.py CHANGED
@@ -1,31 +1,19 @@
1
- import gradio as gr
2
  import torch
 
3
  from diffusers import StableDiffusionPipeline
4
 
5
- # Load model (you can replace this with your own if needed)
6
- pipe = StableDiffusionPipeline.from_pretrained(
7
- "runwayml/stable-diffusion-v1-5",
8
- torch_dtype=torch.float16
9
- ).to("cuda")
10
 
11
- def generate_image(prompt, width, height, guidance_scale):
12
- image = pipe(prompt, width=width, height=height, guidance_scale=guidance_scale).images[0]
13
  return image
14
 
15
- with gr.Blocks() as demo:
16
- gr.Markdown("## 🎨 AI Image Generator - Powered by Stable Diffusion")
17
-
18
- with gr.Row():
19
- prompt = gr.Textbox(label="Enter your prompt", placeholder="e.g. A futuristic city at sunset")
20
-
21
- with gr.Row():
22
- width = gr.Slider(256, 1024, value=512, step=64, label="Width")
23
- height = gr.Slider(256, 1024, value=512, step=64, label="Height")
24
- guidance_scale = gr.Slider(1, 20, value=7.5, step=0.5, label="Guidance Scale")
25
-
26
- generate_btn = gr.Button("Generate Image")
27
- output = gr.Image(label="Generated Image")
28
-
29
- generate_btn.click(fn=generate_image, inputs=[prompt, width, height, guidance_scale], outputs=output)
30
-
31
- demo.launch()
 
 
1
  import torch
2
+ import gradio as gr
3
  from diffusers import StableDiffusionPipeline
4
 
5
+ model_id = "runwayml/stable-diffusion-v1-5" # You can change to your own model
6
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
7
+ pipe = pipe.to("cuda")
 
 
8
 
9
+ def generate(prompt):
10
+ image = pipe(prompt).images[0]
11
  return image
12
 
13
+ gr.Interface(
14
+ fn=generate,
15
+ inputs=gr.Textbox(label="Enter your prompt"),
16
+ outputs=gr.Image(type="pil"),
17
+ title="🎨 AI Image Generator",
18
+ description="Enter a prompt to generate images using Stable Diffusion",
19
+ ).launch()