Spaces:
Running
on
Zero
Running
on
Zero
minor fixes
Browse files
app_v3.py
CHANGED
|
@@ -67,12 +67,19 @@ def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_
|
|
| 67 |
).images[0]
|
| 68 |
return image
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def generate_caption(control_image):
|
| 71 |
if control_image is None:
|
| 72 |
return None, None
|
| 73 |
|
| 74 |
# Generate a detailed caption
|
| 75 |
-
mcaption = model.caption(control_image, length="
|
| 76 |
detailed_caption = mcaption["caption"]
|
| 77 |
print(f"Detailed caption: {detailed_caption}")
|
| 78 |
|
|
@@ -80,8 +87,9 @@ def generate_caption(control_image):
|
|
| 80 |
|
| 81 |
def generate_focus(control_image, focus_list):
|
| 82 |
if control_image is None:
|
| 83 |
-
return None
|
| 84 |
-
|
|
|
|
| 85 |
# Generate a detailed caption
|
| 86 |
focus_query = model.query(control_image, "Please provide a concise but illustrative description of the following area(s) of focus: " + focus_list)
|
| 87 |
focus_description = focus_query["answer"]
|
|
@@ -177,7 +185,10 @@ with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as demo:
|
|
| 177 |
log_prompt = gr.Checkbox(value=True, label="Log", visible=False) # Changed to visible
|
| 178 |
|
| 179 |
gr.Markdown("**Tips:** 8 steps is all you need!")
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
| 181 |
generate_button.click(
|
| 182 |
fn=process_image,
|
| 183 |
inputs=[
|
|
@@ -190,12 +201,15 @@ with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as demo:
|
|
| 190 |
control_image.change(
|
| 191 |
generate_caption,
|
| 192 |
inputs=[control_image],
|
| 193 |
-
outputs=[
|
| 194 |
).then(
|
| 195 |
generate_focus,
|
| 196 |
inputs=[control_image, focus],
|
| 197 |
-
outputs=[prompt]
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
| 199 |
)
|
| 200 |
caption_button.click(
|
| 201 |
fn=generate_caption,
|
|
@@ -203,4 +217,4 @@ with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as demo:
|
|
| 203 |
outputs=[prompt]
|
| 204 |
)
|
| 205 |
|
| 206 |
-
demo.launch(show_error=True)
|
|
|
|
| 67 |
).images[0]
|
| 68 |
return image
|
| 69 |
|
| 70 |
+
def combine_caption_focus(caption, focus):
|
| 71 |
+
if caption is None:
|
| 72 |
+
caption = ""
|
| 73 |
+
if focus is None:
|
| 74 |
+
focus = ""
|
| 75 |
+
return (caption + "\n\n" + focus).strip()
|
| 76 |
+
|
| 77 |
def generate_caption(control_image):
|
| 78 |
if control_image is None:
|
| 79 |
return None, None
|
| 80 |
|
| 81 |
# Generate a detailed caption
|
| 82 |
+
mcaption = model.caption(control_image, length="normal")
|
| 83 |
detailed_caption = mcaption["caption"]
|
| 84 |
print(f"Detailed caption: {detailed_caption}")
|
| 85 |
|
|
|
|
| 87 |
|
| 88 |
def generate_focus(control_image, focus_list):
|
| 89 |
if control_image is None:
|
| 90 |
+
return None
|
| 91 |
+
if focus_list is None:
|
| 92 |
+
return ""
|
| 93 |
# Generate a detailed caption
|
| 94 |
focus_query = model.query(control_image, "Please provide a concise but illustrative description of the following area(s) of focus: " + focus_list)
|
| 95 |
focus_description = focus_query["answer"]
|
|
|
|
| 185 |
log_prompt = gr.Checkbox(value=True, label="Log", visible=False) # Changed to visible
|
| 186 |
|
| 187 |
gr.Markdown("**Tips:** 8 steps is all you need!")
|
| 188 |
+
|
| 189 |
+
caption_state = gr.State()
|
| 190 |
+
focus_state = gr.State()
|
| 191 |
+
|
| 192 |
generate_button.click(
|
| 193 |
fn=process_image,
|
| 194 |
inputs=[
|
|
|
|
| 201 |
control_image.change(
|
| 202 |
generate_caption,
|
| 203 |
inputs=[control_image],
|
| 204 |
+
outputs=[caption_state]
|
| 205 |
).then(
|
| 206 |
generate_focus,
|
| 207 |
inputs=[control_image, focus],
|
| 208 |
+
outputs=[prompt]
|
| 209 |
+
).then(
|
| 210 |
+
combine_caption_focus,
|
| 211 |
+
inputs=[prompt, prompt],
|
| 212 |
+
outputs=[prompt]
|
| 213 |
)
|
| 214 |
caption_button.click(
|
| 215 |
fn=generate_caption,
|
|
|
|
| 217 |
outputs=[prompt]
|
| 218 |
)
|
| 219 |
|
| 220 |
+
demo.launch(show_error=True)
|