LPX55 commited on
Commit
3f9b082
·
verified ·
1 Parent(s): 75e0f2f

Update app_v2.py

Browse files
Files changed (1) hide show
  1. app_v2.py +45 -17
app_v2.py CHANGED
@@ -105,9 +105,14 @@ def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_
105
  ).images[0]
106
  return image
107
 
108
- def process_image(control_image, user_prompt, system_prompt, scale, steps, controlnet_conditioning_scale, guidance_scale, seed, guidance_end, temperature, top_p, max_new_tokens, log_prompt):
 
 
 
 
 
109
  # If no user prompt provided, generate a caption first
110
- if not user_prompt.strip():
111
  caption_gen = caption(
112
  input_image=control_image,
113
  prompt=system_prompt,
@@ -117,19 +122,38 @@ def process_image(control_image, user_prompt, system_prompt, scale, steps, contr
117
  log_prompt=log_prompt
118
  )
119
  # Get the full caption by exhausting the generator
120
- user_prompt = "".join([chunk for chunk in caption_gen])
 
 
 
 
 
 
121
 
122
- # Generate the image using the prompt (either user-provided or generated)
123
- return generate_image(
124
- prompt=user_prompt,
125
- scale=scale,
126
- steps=steps,
127
- control_image=control_image,
128
- controlnet_conditioning_scale=controlnet_conditioning_scale,
129
- guidance_scale=guidance_scale,
130
- seed=seed,
131
- guidance_end=guidance_end
132
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
  with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as iface:
135
  gr.Markdown("⚠️ WIP SPACE - UNFINISHED & BUGGY")
@@ -181,11 +205,15 @@ with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as iface:
181
  generate_button.click(
182
  fn=process_image,
183
  inputs=[
184
- control_image, prompt, system_prompt, scale, steps, controlnet_conditioning_scale,
185
- guidance_scale, seed, guidance_end, temperature_slider, top_p_slider,
 
186
  max_tokens_slider, log_prompt
187
  ],
188
- outputs=[generated_image]
 
 
 
189
  )
190
 
191
  caption_button.click(
 
105
  ).images[0]
106
  return image
107
 
108
+ def process_image(control_image, user_prompt, system_prompt, scale, steps,
109
+ controlnet_conditioning_scale, guidance_scale, seed,
110
+ guidance_end, temperature, top_p, max_new_tokens, log_prompt):
111
+ # Initialize with empty caption
112
+ final_prompt = user_prompt.strip()
113
+
114
  # If no user prompt provided, generate a caption first
115
+ if not final_prompt:
116
  caption_gen = caption(
117
  input_image=control_image,
118
  prompt=system_prompt,
 
122
  log_prompt=log_prompt
123
  )
124
  # Get the full caption by exhausting the generator
125
+ generated_caption = ""
126
+ for chunk in caption_gen:
127
+ generated_caption += chunk
128
+ yield {"__type__": "update_caption", "caption": generated_caption}, None
129
+
130
+ final_prompt = generated_caption
131
+ yield {"__type__": "update_caption", "caption": f"Using caption: {final_prompt}"}, None
132
 
133
+ # Show the final prompt being used
134
+ yield {"__type__": "update_caption", "caption": f"Generating with: {final_prompt}"}, None
135
+
136
+ # Generate the image
137
+ try:
138
+ image = generate_image(
139
+ prompt=final_prompt,
140
+ scale=scale,
141
+ steps=steps,
142
+ control_image=control_image,
143
+ controlnet_conditioning_scale=controlnet_conditioning_scale,
144
+ guidance_scale=guidance_scale,
145
+ seed=seed,
146
+ guidance_end=guidance_end
147
+ )
148
+ yield {"__type__": "update_caption", "caption": f"Completed! Used prompt: {final_prompt}"}, image
149
+ except Exception as e:
150
+ yield {"__type__": "update_caption", "caption": f"Error: {str(e)}"}, None
151
+ raise
152
+
153
+ def handle_outputs(outputs):
154
+ if isinstance(outputs, dict) and outputs.get("__type__") == "update_caption":
155
+ return outputs["caption"], None
156
+ return outputs
157
 
158
  with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as iface:
159
  gr.Markdown("⚠️ WIP SPACE - UNFINISHED & BUGGY")
 
205
  generate_button.click(
206
  fn=process_image,
207
  inputs=[
208
+ control_image, prompt, system_prompt, scale, steps,
209
+ controlnet_conditioning_scale, guidance_scale, seed,
210
+ guidance_end, temperature_slider, top_p_slider,
211
  max_tokens_slider, log_prompt
212
  ],
213
+ outputs=[output_caption, generated_image]
214
+ ).then(
215
+ handle_outputs,
216
+ outputs=[output_caption, generated_image]
217
  )
218
 
219
  caption_button.click(