Spaces:
Running
on
Zero
Running
on
Zero
kayfahaarukku
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,7 @@ pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.conf
|
|
20 |
|
21 |
# Function to generate an image
|
22 |
@spaces.GPU() # Adjust the duration as needed
|
23 |
-
def generate_image(prompt, negative_prompt, use_defaults,
|
24 |
pipe.to('cuda') # Move the model to GPU when the function is called
|
25 |
|
26 |
if randomize_seed:
|
@@ -34,6 +34,7 @@ def generate_image(prompt, negative_prompt, use_defaults, width, height, guidanc
|
|
34 |
progress(step / num_inference_steps)
|
35 |
return
|
36 |
|
|
|
37 |
image = pipe(
|
38 |
prompt,
|
39 |
negative_prompt=negative_prompt,
|
@@ -52,12 +53,12 @@ def generate_image(prompt, negative_prompt, use_defaults, width, height, guidanc
|
|
52 |
return image, seed
|
53 |
|
54 |
# Define Gradio interface
|
55 |
-
def interface_fn(prompt, negative_prompt, use_defaults,
|
56 |
-
image, seed = generate_image(prompt, negative_prompt, use_defaults,
|
57 |
return image, seed, gr.update(value=seed)
|
58 |
|
59 |
def reset_inputs():
|
60 |
-
return gr.update(value=''), gr.update(value=''), gr.update(value=True), gr.update(value=
|
61 |
|
62 |
with gr.Blocks(title="UrangDiffusion 1.0 Demo", theme="NoCrypt/miku@1.2.1") as demo:
|
63 |
gr.HTML(
|
@@ -68,8 +69,14 @@ with gr.Blocks(title="UrangDiffusion 1.0 Demo", theme="NoCrypt/miku@1.2.1") as d
|
|
68 |
prompt_input = gr.Textbox(lines=2, placeholder="Enter prompt here", label="Prompt")
|
69 |
negative_prompt_input = gr.Textbox(lines=2, placeholder="Enter negative prompt here", label="Negative Prompt")
|
70 |
use_defaults_input = gr.Checkbox(label="Use Default Quality Tags and Negative Prompt", value=True)
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
guidance_scale_input = gr.Slider(minimum=1, maximum=20, step=0.5, label="Guidance Scale", value=7)
|
74 |
num_inference_steps_input = gr.Slider(minimum=1, maximum=100, step=1, label="Number of Inference Steps", value=28)
|
75 |
seed_input = gr.Slider(minimum=0, maximum=99999999, step=1, label="Seed", value=0, interactive=True)
|
@@ -83,7 +90,7 @@ with gr.Blocks(title="UrangDiffusion 1.0 Demo", theme="NoCrypt/miku@1.2.1") as d
|
|
83 |
generate_button.click(
|
84 |
interface_fn,
|
85 |
inputs=[
|
86 |
-
prompt_input, negative_prompt_input, use_defaults_input,
|
87 |
],
|
88 |
outputs=[output_image, seed_input]
|
89 |
)
|
@@ -92,7 +99,7 @@ with gr.Blocks(title="UrangDiffusion 1.0 Demo", theme="NoCrypt/miku@1.2.1") as d
|
|
92 |
reset_inputs,
|
93 |
inputs=[],
|
94 |
outputs=[
|
95 |
-
prompt_input, negative_prompt_input, use_defaults_input,
|
96 |
]
|
97 |
)
|
98 |
|
|
|
20 |
|
21 |
# Function to generate an image
|
22 |
@spaces.GPU() # Adjust the duration as needed
|
23 |
+
def generate_image(prompt, negative_prompt, use_defaults, resolution, guidance_scale, num_inference_steps, seed, randomize_seed, progress=gr.Progress()):
|
24 |
pipe.to('cuda') # Move the model to GPU when the function is called
|
25 |
|
26 |
if randomize_seed:
|
|
|
34 |
progress(step / num_inference_steps)
|
35 |
return
|
36 |
|
37 |
+
width, height = map(int, resolution.split('x'))
|
38 |
image = pipe(
|
39 |
prompt,
|
40 |
negative_prompt=negative_prompt,
|
|
|
53 |
return image, seed
|
54 |
|
55 |
# Define Gradio interface
|
56 |
+
def interface_fn(prompt, negative_prompt, use_defaults, resolution, guidance_scale, num_inference_steps, seed, randomize_seed, progress=gr.Progress()):
|
57 |
+
image, seed = generate_image(prompt, negative_prompt, use_defaults, resolution, guidance_scale, num_inference_steps, seed, randomize_seed, progress)
|
58 |
return image, seed, gr.update(value=seed)
|
59 |
|
60 |
def reset_inputs():
|
61 |
+
return gr.update(value=''), gr.update(value=''), gr.update(value=True), gr.update(value='1024x1024'), gr.update(value=7), gr.update(value=28), gr.update(value=0), gr.update(value=False)
|
62 |
|
63 |
with gr.Blocks(title="UrangDiffusion 1.0 Demo", theme="NoCrypt/miku@1.2.1") as demo:
|
64 |
gr.HTML(
|
|
|
69 |
prompt_input = gr.Textbox(lines=2, placeholder="Enter prompt here", label="Prompt")
|
70 |
negative_prompt_input = gr.Textbox(lines=2, placeholder="Enter negative prompt here", label="Negative Prompt")
|
71 |
use_defaults_input = gr.Checkbox(label="Use Default Quality Tags and Negative Prompt", value=True)
|
72 |
+
resolution_input = gr.Radio(
|
73 |
+
choices=[
|
74 |
+
"1024x1024", "1152x896", "896x1152", "1216x832", "832x1216",
|
75 |
+
"1344x768", "768x1344", "1536x640", "640x1536"
|
76 |
+
],
|
77 |
+
label="Resolution",
|
78 |
+
value="896x1152"
|
79 |
+
)
|
80 |
guidance_scale_input = gr.Slider(minimum=1, maximum=20, step=0.5, label="Guidance Scale", value=7)
|
81 |
num_inference_steps_input = gr.Slider(minimum=1, maximum=100, step=1, label="Number of Inference Steps", value=28)
|
82 |
seed_input = gr.Slider(minimum=0, maximum=99999999, step=1, label="Seed", value=0, interactive=True)
|
|
|
90 |
generate_button.click(
|
91 |
interface_fn,
|
92 |
inputs=[
|
93 |
+
prompt_input, negative_prompt_input, use_defaults_input, resolution_input, guidance_scale_input, num_inference_steps_input, seed_input, randomize_seed_input
|
94 |
],
|
95 |
outputs=[output_image, seed_input]
|
96 |
)
|
|
|
99 |
reset_inputs,
|
100 |
inputs=[],
|
101 |
outputs=[
|
102 |
+
prompt_input, negative_prompt_input, use_defaults_input, resolution_input, guidance_scale_input, num_inference_steps_input, seed_input, randomize_seed_input
|
103 |
]
|
104 |
)
|
105 |
|