Spaces:
Running
on
Zero
Running
on
Zero
TheAwakenOne
commited on
Commit
•
ab9ca3b
1
Parent(s):
44f98f9
Updates
Browse files
app.py
CHANGED
@@ -18,43 +18,68 @@ def initialize_model():
|
|
18 |
def generate_image(
|
19 |
prompt,
|
20 |
guidance_scale=3.5,
|
21 |
-
num_steps=25, # Changed default to 25
|
22 |
width=1024,
|
23 |
height=1024
|
24 |
):
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# Create the Gradio interface
|
44 |
demo = gr.Interface(
|
45 |
fn=generate_image,
|
46 |
inputs=[
|
47 |
-
gr.Textbox(
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
],
|
52 |
outputs=gr.Image(type="pil", label="Generated Image"),
|
53 |
title="Flux Image Generator (Zero-GPU)",
|
54 |
-
description="Generate images using Freepik's Flux model with Zero-GPU allocation. Using 25 steps and random seed for each generation.",
|
55 |
examples=[
|
56 |
["A close-up image of a green alien with fluorescent skin in the middle of a dark purple forest", 3.5, 1024, 1024],
|
57 |
-
["A serene landscape with mountains at sunset", 3.5, 1024, 1024]
|
58 |
]
|
59 |
)
|
60 |
|
|
|
18 |
def generate_image(
|
19 |
prompt,
|
20 |
guidance_scale=3.5,
|
|
|
21 |
width=1024,
|
22 |
height=1024
|
23 |
):
|
24 |
+
try:
|
25 |
+
# Initialize model within the GPU context
|
26 |
+
pipe = initialize_model()
|
27 |
+
|
28 |
+
# Generate random seed
|
29 |
+
seed = random.randint(1, 1000000)
|
30 |
+
|
31 |
+
with torch.inference_mode():
|
32 |
+
image = pipe(
|
33 |
+
prompt=prompt,
|
34 |
+
generator=torch.Generator(device="cuda").manual_seed(seed),
|
35 |
+
num_inference_steps=25, # Fixed steps
|
36 |
+
guidance_scale=guidance_scale,
|
37 |
+
height=height,
|
38 |
+
width=width,
|
39 |
+
).images[0]
|
40 |
+
|
41 |
+
return image
|
42 |
+
except Exception as e:
|
43 |
+
print(f"Error during image generation: {str(e)}")
|
44 |
+
raise e
|
45 |
|
46 |
# Create the Gradio interface
|
47 |
demo = gr.Interface(
|
48 |
fn=generate_image,
|
49 |
inputs=[
|
50 |
+
gr.Textbox(
|
51 |
+
label="Prompt",
|
52 |
+
placeholder="Enter your image description here...",
|
53 |
+
value="A serene landscape with mountains at sunset"
|
54 |
+
),
|
55 |
+
gr.Slider(
|
56 |
+
minimum=1,
|
57 |
+
maximum=20,
|
58 |
+
value=3.5,
|
59 |
+
label="Guidance Scale",
|
60 |
+
step=0.5
|
61 |
+
),
|
62 |
+
gr.Slider(
|
63 |
+
minimum=128,
|
64 |
+
maximum=1024,
|
65 |
+
value=1024,
|
66 |
+
label="Width",
|
67 |
+
step=64
|
68 |
+
),
|
69 |
+
gr.Slider(
|
70 |
+
minimum=128,
|
71 |
+
maximum=1024,
|
72 |
+
value=1024,
|
73 |
+
label="Height",
|
74 |
+
step=64
|
75 |
+
)
|
76 |
],
|
77 |
outputs=gr.Image(type="pil", label="Generated Image"),
|
78 |
title="Flux Image Generator (Zero-GPU)",
|
79 |
+
description="Generate images using Freepik's Flux model with Zero-GPU allocation. Using 25 fixed steps and random seed for each generation.",
|
80 |
examples=[
|
81 |
["A close-up image of a green alien with fluorescent skin in the middle of a dark purple forest", 3.5, 1024, 1024],
|
82 |
+
["A serene landscape with mountains at sunset", 3.5, 1024, 1024]
|
83 |
]
|
84 |
)
|
85 |
|