Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,18 @@
|
|
1 |
-
|
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 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
1 |
+
from diffusers import StableDiffusionPipeline
|
|
|
2 |
import torch
|
3 |
import random
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def generate_image(prompt):
|
6 |
+
# Load the model
|
7 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
8 |
+
"stabilityai/stable-diffusion-2-1",
|
9 |
+
use_auth_token="YOUR_HF_TOKEN" # Replace with your token
|
10 |
+
)
|
11 |
+
|
12 |
+
# Random seed for uniqueness
|
13 |
+
seed = random.randint(0, 1000000)
|
14 |
+
generator = torch.Generator().manual_seed(seed)
|
15 |
+
|
16 |
+
# Generate image
|
17 |
image = pipe(prompt, generator=generator).images[0]
|
18 |
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|