Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,45 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
|
3 |
-
import torch
|
4 |
-
import random
|
5 |
-
|
6 |
-
# No
|
7 |
-
model_id = "stabilityai/stable-diffusion-2-1-base"
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
).launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
|
3 |
+
import torch
|
4 |
+
import random
|
5 |
+
|
6 |
+
# No token needed
|
7 |
+
model_id = "stabilityai/stable-diffusion-2-1-base" # β
New model ID
|
8 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id) # β
Simplified
|
9 |
+
|
10 |
+
# Add before initializing the pipeline
|
11 |
+
from diffusers import EulerDiscreteScheduler
|
12 |
+
|
13 |
+
scheduler = EulerDiscreteScheduler.from_pretrained(
|
14 |
+
model_id,
|
15 |
+
subfolder="scheduler" # β
Required for SD v2
|
16 |
+
)
|
17 |
+
|
18 |
+
# Include in pipeline initialization
|
19 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
20 |
+
model_id,
|
21 |
+
scheduler=scheduler, # β
Add this
|
22 |
+
torch_dtype=torch.float32
|
23 |
+
)
|
24 |
+
|
25 |
+
# Old (might try to use GPU):
|
26 |
+
pipe.to("cuda")
|
27 |
+
|
28 |
+
# New (force CPU):
|
29 |
+
pipe.to("cpu") # β
Explicit CPU usage
|
30 |
+
|
31 |
+
pipe.enable_attention_slicing() # β
Reduces RAM usage
|
32 |
+
|
33 |
+
def generate_image(prompt):
|
34 |
+
seed = random.randint(0, 1000000) # Random seed
|
35 |
+
generator = torch.Generator("cpu").manual_seed(seed)
|
36 |
+
image = pipe(prompt, generator=generator).images[0]
|
37 |
+
return image
|
38 |
+
|
39 |
+
# Create interface
|
40 |
+
gr.Interface(
|
41 |
+
fn=generate_image,
|
42 |
+
inputs=gr.Textbox(label="Type anything (e.g., 'dog')"),
|
43 |
+
outputs=gr.Image(label="Generated Image"),
|
44 |
+
title="Free AI Image Generator"
|
45 |
).launch()
|