Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,9 @@ import string
|
|
23 |
import random, time, math
|
24 |
import os
|
25 |
|
26 |
-
|
|
|
|
|
27 |
|
28 |
import src.flux.generate
|
29 |
from src.flux.generate import generate_from_test_sample, seed_everything
|
@@ -116,6 +118,7 @@ model.config = config
|
|
116 |
|
117 |
run_mode = "mod_only"
|
118 |
store_attn_map = False
|
|
|
119 |
|
120 |
num_inputs = 2
|
121 |
|
@@ -254,10 +257,10 @@ def generate_image(
|
|
254 |
|
255 |
src_inputs = []
|
256 |
use_words = []
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
print(f"Temporary directory created: {temp_dir}")
|
262 |
for i, (image_path, caption) in enumerate(zip(images, captions)):
|
263 |
if image_path:
|
@@ -270,7 +273,7 @@ def generate_image(
|
|
270 |
prompt = prompt.replace(f"ENT{i+1}", caption)
|
271 |
|
272 |
image = resize_keep_aspect_ratio(Image.open(image_path), 768)
|
273 |
-
save_path = f"{temp_dir}/tmp_resized_input_{i}.png"
|
274 |
image.save(save_path)
|
275 |
|
276 |
input_image_path = save_path
|
@@ -308,7 +311,7 @@ def generate_image(
|
|
308 |
),
|
309 |
]
|
310 |
|
311 |
-
json_dump(test_sample, f"{temp_dir}/test_sample.json", 'utf-8')
|
312 |
assert single_attention == True
|
313 |
target_size = int(round((target_width * target_height) ** 0.5) // 16 * 16)
|
314 |
print(test_sample)
|
@@ -435,25 +438,6 @@ def start_session(request: gr.Request):
|
|
435 |
"""
|
436 |
return request.session_hash
|
437 |
|
438 |
-
|
439 |
-
# Cleanup on unload
|
440 |
-
def cleanup(request: gr.Request):
|
441 |
-
"""
|
442 |
-
Clean up session-specific directories and temporary files when the user session ends.
|
443 |
-
|
444 |
-
This function is triggered when the Gradio demo is unloaded (e.g., when the user
|
445 |
-
closes the browser tab or navigates away). It removes all temporary files and
|
446 |
-
directories created during the user's session to free up storage space.
|
447 |
-
|
448 |
-
Args:
|
449 |
-
request (gr.Request): Gradio request object containing session information
|
450 |
-
"""
|
451 |
-
sid = request.session_hash
|
452 |
-
if sid:
|
453 |
-
d1 = os.path.join(os.environ["XVERSE_OUTPUT_DATA"], sid)
|
454 |
-
shutil.rmtree(d1, ignore_errors=True)
|
455 |
-
|
456 |
-
|
457 |
css = """
|
458 |
#col-container {
|
459 |
margin: 0 auto;
|
@@ -599,7 +583,6 @@ if __name__ == "__main__":
|
|
599 |
vlm_btns[i].click(vlm_img_caption, inputs=[images[i]], outputs=[captions[i]])
|
600 |
accordion_states[i].change(fn=lambda x, state, index=i: change_accordion(x, index, state), inputs=[accordion_states[i], indices_state], outputs=[accordions[i], indices_state])
|
601 |
|
602 |
-
demo.unload(cleanup)
|
603 |
|
604 |
demo.queue()
|
605 |
demo.launch()
|
|
|
23 |
import random, time, math
|
24 |
import os
|
25 |
|
26 |
+
|
27 |
+
os.environ["NCCL_P2P_DISABLE"]="1"
|
28 |
+
os.environ["NCCL_IB_DISABLE"]="1"
|
29 |
|
30 |
import src.flux.generate
|
31 |
from src.flux.generate import generate_from_test_sample, seed_everything
|
|
|
118 |
|
119 |
run_mode = "mod_only"
|
120 |
store_attn_map = False
|
121 |
+
run_name = time.strftime("%m%d-%H%M")
|
122 |
|
123 |
num_inputs = 2
|
124 |
|
|
|
257 |
|
258 |
src_inputs = []
|
259 |
use_words = []
|
260 |
+
cur_run_time = time.strftime("%m%d-%H%M%S")
|
261 |
+
tmp_dir_root = f"tmp/gradio_demo/{run_name}"
|
262 |
+
temp_dir = f"{tmp_dir_root}/{session_id}/{cur_run_time}_{generate_random_string(4)}"
|
263 |
+
os.makedirs(temp_dir, exist_ok=True)
|
264 |
print(f"Temporary directory created: {temp_dir}")
|
265 |
for i, (image_path, caption) in enumerate(zip(images, captions)):
|
266 |
if image_path:
|
|
|
273 |
prompt = prompt.replace(f"ENT{i+1}", caption)
|
274 |
|
275 |
image = resize_keep_aspect_ratio(Image.open(image_path), 768)
|
276 |
+
save_path = f"{temp_dir}/{session_id}/tmp_resized_input_{i}.png"
|
277 |
image.save(save_path)
|
278 |
|
279 |
input_image_path = save_path
|
|
|
311 |
),
|
312 |
]
|
313 |
|
314 |
+
json_dump(test_sample, f"{temp_dir}/{session_id}/test_sample.json", 'utf-8')
|
315 |
assert single_attention == True
|
316 |
target_size = int(round((target_width * target_height) ** 0.5) // 16 * 16)
|
317 |
print(test_sample)
|
|
|
438 |
"""
|
439 |
return request.session_hash
|
440 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
441 |
css = """
|
442 |
#col-container {
|
443 |
margin: 0 auto;
|
|
|
583 |
vlm_btns[i].click(vlm_img_caption, inputs=[images[i]], outputs=[captions[i]])
|
584 |
accordion_states[i].change(fn=lambda x, state, index=i: change_accordion(x, index, state), inputs=[accordion_states[i], indices_state], outputs=[accordions[i], indices_state])
|
585 |
|
|
|
586 |
|
587 |
demo.queue()
|
588 |
demo.launch()
|