Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,19 @@
|
|
1 |
-
import gradio as gr
|
2 |
import torch
|
|
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
|
5 |
-
|
6 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
7 |
-
|
8 |
-
torch_dtype=torch.float16
|
9 |
-
).to("cuda")
|
10 |
|
11 |
-
def
|
12 |
-
image = pipe(prompt
|
13 |
return image
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|