kayfahaarukku commited on
Commit
c9c788f
·
verified ·
1 Parent(s): 517b8d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
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, width, height, 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,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, width, height, guidance_scale, num_inference_steps, seed, randomize_seed, progress=gr.Progress()):
56
- image, seed = generate_image(prompt, negative_prompt, use_defaults, width, height, guidance_scale, num_inference_steps, seed, randomize_seed, progress)
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=832), gr.update(value=1216), gr.update(value=7), gr.update(value=28), gr.update(value=0), gr.update(value=False)
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
- width_input = gr.Slider(minimum=256, maximum=2048, step=32, label="Width", value=832)
72
- height_input = gr.Slider(minimum=256, maximum=2048, step=32, label="Height", value=1216)
 
 
 
 
 
 
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, width_input, height_input, guidance_scale_input, num_inference_steps_input, seed_input, randomize_seed_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, width_input, height_input, guidance_scale_input, num_inference_steps_input, seed_input, randomize_seed_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