LPX55 commited on
Commit
3ce057d
·
verified ·
1 Parent(s): d086d94

Update app_v4.py

Browse files
Files changed (1) hide show
  1. app_v4.py +47 -1
app_v4.py CHANGED
@@ -26,6 +26,30 @@ logging.basicConfig(level=logging.DEBUG)
26
  logger = logging.getLogger(__name__)
27
  #############################
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
30
  MAX_SEED = 1000000
31
 
@@ -157,6 +181,20 @@ def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_
157
  # print("Type: " + str(type(image)))
158
  return image
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  def process_image(control_image, user_prompt, system_prompt, scale, steps,
161
  controlnet_conditioning_scale, guidance_scale, seed,
162
  guidance_end, temperature, max_new_tokens, log_prompt):
@@ -210,11 +248,14 @@ with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as demo:
210
  with gr.Column(scale=1):
211
  prompt = gr.Textbox(lines=4, info="Enter your prompt here or wait for auto-generation...", label="Image Description")
212
  focus = gr.Textbox(label="Area(s) of Focus", info="e.g. 'face', 'eyes', 'hair', 'clothes', 'background', etc.", value="clothing material, textures, ethnicity")
213
- scale = gr.Slider(1, 3, value=1, label="Scale (Upscale Factor)", step=0.25)
214
  with gr.Row():
215
  generate_button = gr.Button("Generate Image", variant="primary")
216
  caption_button = gr.Button("Generate Caption", variant="secondary")
217
  with gr.Column(scale=1):
 
 
 
218
  seed = gr.Slider(0, MAX_SEED, value=42, label="Seed", step=1)
219
  steps = gr.Slider(2, 16, value=8, label="Steps", step=1)
220
  controlnet_conditioning_scale = gr.Slider(0, 1, value=0.6, label="ControlNet Scale")
@@ -296,6 +337,11 @@ with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as demo:
296
  inputs=[caption_state, focus_state],
297
  outputs=[prompt]
298
  )
 
 
 
 
 
299
  def hello(profile: gr.OAuthProfile | None) -> str:
300
  if profile is None:
301
  return "Hello guest! There is a bug with HF ZeroGPUs that are afffecting some usage on certain spaces. Testing out some possible solutions."
 
26
  logger = logging.getLogger(__name__)
27
  #############################
28
 
29
+ presets = {
30
+ "Strict Upscale": {
31
+ "scale": 1.0,
32
+ "steps": 8,
33
+ "controlnet_conditioning_scale": 0.75,
34
+ "guidance_scale": 4.0,
35
+ "guidance_end": 0.9
36
+ },
37
+ "Creative Upscale": {
38
+ "scale": 2.0,
39
+ "steps": 6,
40
+ "controlnet_conditioning_scale": 0.42,
41
+ "guidance_scale": 3.0,
42
+ "guidance_end": 0.5
43
+ },
44
+ "High Detail Upscale": {
45
+ "scale": 1.25,
46
+ "steps": 10,
47
+ "controlnet_conditioning_scale": 0.9,
48
+ "guidance_scale": 10.0,
49
+ "guidance_end": 0.9
50
+ }
51
+ }
52
+
53
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
54
  MAX_SEED = 1000000
55
 
 
181
  # print("Type: " + str(type(image)))
182
  return image
183
 
184
+ def update_parameters(preset):
185
+ if preset in presets:
186
+ params = presets[preset]
187
+ return (
188
+ params["scale"],
189
+ params["steps"],
190
+ params["controlnet_conditioning_scale"],
191
+ params["guidance_scale"],
192
+ params["guidance_end"]
193
+ )
194
+ else:
195
+ # Default values if preset is not found
196
+ return 1.0, 8, 0.6, 3.5, 1.0
197
+
198
  def process_image(control_image, user_prompt, system_prompt, scale, steps,
199
  controlnet_conditioning_scale, guidance_scale, seed,
200
  guidance_end, temperature, max_new_tokens, log_prompt):
 
248
  with gr.Column(scale=1):
249
  prompt = gr.Textbox(lines=4, info="Enter your prompt here or wait for auto-generation...", label="Image Description")
250
  focus = gr.Textbox(label="Area(s) of Focus", info="e.g. 'face', 'eyes', 'hair', 'clothes', 'background', etc.", value="clothing material, textures, ethnicity")
251
+ scale = gr.Slider(1, 3, value=1, label="Scale (Upscale Factor)", step=0.1)
252
  with gr.Row():
253
  generate_button = gr.Button("Generate Image", variant="primary")
254
  caption_button = gr.Button("Generate Caption", variant="secondary")
255
  with gr.Column(scale=1):
256
+ with gr.Row():
257
+ preset_choices = list(presets.keys())
258
+ preset_radio = gr.Radio(choices=preset_choices, label="Select Preset", value=preset_choices[0])
259
  seed = gr.Slider(0, MAX_SEED, value=42, label="Seed", step=1)
260
  steps = gr.Slider(2, 16, value=8, label="Steps", step=1)
261
  controlnet_conditioning_scale = gr.Slider(0, 1, value=0.6, label="ControlNet Scale")
 
337
  inputs=[caption_state, focus_state],
338
  outputs=[prompt]
339
  )
340
+ preset_radio.change(
341
+ fn=update_parameters,
342
+ inputs=[preset_radio],
343
+ outputs=[scale, steps, controlnet_conditioning_scale, guidance_scale, guidance_end]
344
+ )
345
  def hello(profile: gr.OAuthProfile | None) -> str:
346
  if profile is None:
347
  return "Hello guest! There is a bug with HF ZeroGPUs that are afffecting some usage on certain spaces. Testing out some possible solutions."