Spaces:
Running
on
Zero
Running
on
Zero
minor
Browse files
app_v3.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import subprocess
|
| 2 |
-
subprocess.run("rm -rf /data-nvme/zerogpu-offload/*", env={}, shell=True)
|
| 3 |
|
| 4 |
import torch
|
| 5 |
import spaces
|
|
@@ -113,6 +113,17 @@ def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_
|
|
| 113 |
).images[0]
|
| 114 |
return image
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
def process_image(control_image, user_prompt, system_prompt, scale, steps,
|
| 117 |
controlnet_conditioning_scale, guidance_scale, seed,
|
| 118 |
guidance_end, temperature, top_p, max_new_tokens, log_prompt):
|
|
@@ -125,22 +136,7 @@ def process_image(control_image, user_prompt, system_prompt, scale, steps,
|
|
| 125 |
mcaption = model.caption(control_image, length="long")
|
| 126 |
detailed_caption = mcaption["caption"]
|
| 127 |
print(f"Detailed caption: {detailed_caption}")
|
| 128 |
-
|
| 129 |
-
# caption_gen = caption(
|
| 130 |
-
# input_image=control_image,
|
| 131 |
-
# prompt=system_prompt,
|
| 132 |
-
# temperature=temperature,
|
| 133 |
-
# top_p=top_p,
|
| 134 |
-
# max_new_tokens=max_new_tokens,
|
| 135 |
-
# log_prompt=log_prompt
|
| 136 |
-
# )
|
| 137 |
-
|
| 138 |
-
# Get the full caption by exhausting the generator
|
| 139 |
-
# generated_caption = ""
|
| 140 |
-
# for chunk in caption_gen:
|
| 141 |
-
# generated_caption += chunk
|
| 142 |
-
# yield generated_caption, None # Update caption in real-time
|
| 143 |
-
|
| 144 |
final_prompt = detailed_caption
|
| 145 |
yield f"Using caption: {final_prompt}", None, final_prompt
|
| 146 |
|
|
@@ -225,11 +221,15 @@ with gr.Blocks(title="FLUX Turbo Upscaler", fill_height=True) as demo:
|
|
| 225 |
],
|
| 226 |
outputs=[output_caption, generated_image, prompt]
|
| 227 |
)
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
-
demo.launch()
|
|
|
|
| 1 |
import subprocess
|
| 2 |
+
# subprocess.run("rm -rf /data-nvme/zerogpu-offload/*", env={}, shell=True)
|
| 3 |
|
| 4 |
import torch
|
| 5 |
import spaces
|
|
|
|
| 113 |
).images[0]
|
| 114 |
return image
|
| 115 |
|
| 116 |
+
def generate_caption(control_image):
|
| 117 |
+
if control_image is None:
|
| 118 |
+
return None, None
|
| 119 |
+
|
| 120 |
+
# Generate a detailed caption
|
| 121 |
+
mcaption = model.caption(control_image, length="long")
|
| 122 |
+
detailed_caption = mcaption["caption"]
|
| 123 |
+
print(f"Detailed caption: {detailed_caption}")
|
| 124 |
+
|
| 125 |
+
return detailed_caption
|
| 126 |
+
|
| 127 |
def process_image(control_image, user_prompt, system_prompt, scale, steps,
|
| 128 |
controlnet_conditioning_scale, guidance_scale, seed,
|
| 129 |
guidance_end, temperature, top_p, max_new_tokens, log_prompt):
|
|
|
|
| 136 |
mcaption = model.caption(control_image, length="long")
|
| 137 |
detailed_caption = mcaption["caption"]
|
| 138 |
print(f"Detailed caption: {detailed_caption}")
|
| 139 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
final_prompt = detailed_caption
|
| 141 |
yield f"Using caption: {final_prompt}", None, final_prompt
|
| 142 |
|
|
|
|
| 221 |
],
|
| 222 |
outputs=[output_caption, generated_image, prompt]
|
| 223 |
)
|
| 224 |
+
control_image.change(
|
| 225 |
+
generate_caption,
|
| 226 |
+
inputs=[control_image],
|
| 227 |
+
outputs=[prompt]
|
| 228 |
+
)
|
| 229 |
+
caption_button.click(
|
| 230 |
+
fn=generate_caption,
|
| 231 |
+
inputs=[control_image],
|
| 232 |
+
outputs=[prompt]
|
| 233 |
+
)
|
| 234 |
|
| 235 |
+
demo.launch(show_error=True)
|