Spaces:
Running
on
Zero
Running
on
Zero
PseudoTerminal X
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,18 +4,30 @@ import gradio as gr
|
|
4 |
import spaces
|
5 |
|
6 |
# Load the pre-trained diffusion model
|
7 |
-
pipe = DiffusionPipeline.from_pretrained('ptx0/
|
8 |
pipe.to('cuda')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Define the image generation function with adjustable parameters and a progress bar
|
11 |
@spaces.GPU
|
12 |
-
def generate(prompt, guidance_scale, guidance_rescale, num_inference_steps, negative_prompt):
|
|
|
13 |
return pipe(
|
14 |
prompt,
|
15 |
negative_prompt=negative_prompt,
|
16 |
guidance_scale=guidance_scale,
|
17 |
guidance_rescale=guidance_rescale,
|
18 |
-
num_inference_steps=num_inference_steps
|
|
|
19 |
).images
|
20 |
|
21 |
# Example prompts to demonstrate the model's capabilities
|
@@ -25,18 +37,19 @@ example_prompts = [
|
|
25 |
["An abstract painting of joy and energy in bright colors", 9.0, 30, "dark, dull"]
|
26 |
]
|
27 |
|
28 |
-
# Create a Gradio interface
|
29 |
iface = gr.Interface(
|
30 |
fn=generate,
|
31 |
inputs=[
|
32 |
gr.Text(label="Enter your prompt"),
|
33 |
-
gr.Slider(1, 20, step=0.1, label="Guidance Scale", value=11.5)
|
34 |
gr.Slider(0, 1, step=0.1, label="Rescale classifier-free guidance", value=0.7),
|
35 |
gr.Slider(1, 50, step=1, label="Number of Inference Steps", value=25),
|
|
|
36 |
gr.Text(value="underexposed, blurry, ugly, washed-out", label="Negative Prompt")
|
37 |
],
|
38 |
outputs=gr.Gallery(height=1024, min_width=1024, columns=2),
|
39 |
examples=example_prompts,
|
40 |
-
title="
|
41 |
-
description="
|
42 |
).launch()
|
|
|
4 |
import spaces
|
5 |
|
6 |
# Load the pre-trained diffusion model
|
7 |
+
pipe = DiffusionPipeline.from_pretrained('ptx0/pseudo-flex-v2', torch_dtype=torch.bfloat16)
|
8 |
pipe.to('cuda')
|
9 |
+
import re
|
10 |
+
|
11 |
+
def extract_resolution(resolution_str):
|
12 |
+
match = re.match(r'(\d+)x(\d+)', resolution_str)
|
13 |
+
if match:
|
14 |
+
width = int(match.group(1))
|
15 |
+
height = int(match.group(2))
|
16 |
+
return (width, height)
|
17 |
+
else:
|
18 |
+
return None
|
19 |
|
20 |
# Define the image generation function with adjustable parameters and a progress bar
|
21 |
@spaces.GPU
|
22 |
+
def generate(prompt, guidance_scale, guidance_rescale, num_inference_steps, resolution, negative_prompt):
|
23 |
+
width, height = extract_resolution(resolution) or (1024, 1024)
|
24 |
return pipe(
|
25 |
prompt,
|
26 |
negative_prompt=negative_prompt,
|
27 |
guidance_scale=guidance_scale,
|
28 |
guidance_rescale=guidance_rescale,
|
29 |
+
num_inference_steps=num_inference_steps,
|
30 |
+
width=width, height=height
|
31 |
).images
|
32 |
|
33 |
# Example prompts to demonstrate the model's capabilities
|
|
|
37 |
["An abstract painting of joy and energy in bright colors", 9.0, 30, "dark, dull"]
|
38 |
]
|
39 |
|
40 |
+
# Create a Gradio interface, 1024x1024,1152x960,896x1152
|
41 |
iface = gr.Interface(
|
42 |
fn=generate,
|
43 |
inputs=[
|
44 |
gr.Text(label="Enter your prompt"),
|
45 |
+
gr.Slider(1, 20, step=0.1, label="Guidance Scale", value=11.5)
|
46 |
gr.Slider(0, 1, step=0.1, label="Rescale classifier-free guidance", value=0.7),
|
47 |
gr.Slider(1, 50, step=1, label="Number of Inference Steps", value=25),
|
48 |
+
gr.Radio(["1024x1024", "1152x960", "896x1152"], label="Resolution", value="1152x960"),
|
49 |
gr.Text(value="underexposed, blurry, ugly, washed-out", label="Negative Prompt")
|
50 |
],
|
51 |
outputs=gr.Gallery(height=1024, min_width=1024, columns=2),
|
52 |
examples=example_prompts,
|
53 |
+
title="Flex v2 (SD 2.1-v) Demonstration",
|
54 |
+
description="Flex v2 is a multi-aspect finetune of SD 2.1-v (768px) that is up-sized to a base resolution of 1 megapixel (1024px). This model utilises a zero-terminal SNR noise schedule, formulated to allow for very dark and very bright images."
|
55 |
).launch()
|