ZhouZJ36DL commited on
Commit
c28416b
·
1 Parent(s): a216e74

modified: app.py

Browse files
app.py CHANGED
@@ -41,6 +41,11 @@ ae = load_ae(name, device="cpu" if offload else torch_device)
41
  t5 = load_t5(device, max_length=256 if name == "flux-schnell" else 512)
42
  clip = load_clip(device)
43
  model = load_flow_model(name, device="cpu" if offload else torch_device)
 
 
 
 
 
44
  is_schnell = False
45
  add_sampling_metadata = True
46
 
@@ -51,8 +56,14 @@ if os.path.exists("history_gradio/history.safetensors"):
51
  out_root = 'src/gradio_utils/gradio_outputs'
52
  if not os.path.exists(out_root):
53
  os.makedirs(out_root)
54
- name_dir = f'exp_{len(os.listdir(out_root))+1}'
 
 
 
 
 
55
  output_dir = os.path.join(out_root, name_dir)
 
56
  if not os.path.exists(output_dir):
57
  os.makedirs(output_dir)
58
  if not os.path.exists("heatmap"):
@@ -73,11 +84,17 @@ def reset():
73
  if os.path.exists("history_gradio/history.safetensors"):
74
  os.remove("history_gradio/history.safetensors")
75
 
76
- out_root = 'src/gradio_utils/gradio_outputs'
77
  if not os.path.exists(out_root):
78
  os.makedirs(out_root)
79
- name_dir = f'exp_{len(os.listdir(out_root))+1}'
 
 
 
 
 
80
  output_dir = os.path.join(out_root, name_dir)
 
81
  if not os.path.exists(output_dir):
82
  os.makedirs(output_dir)
83
  if not os.path.exists("heatmap"):
@@ -128,7 +145,7 @@ def generate_image(
128
  init_image=None,
129
  image2image_strength=0.0,
130
  ):
131
- global ae, t5, clip, model, name, is_schnell, output_dir, add_sampling_metadata, offload
132
  device = "cuda" if torch.cuda.is_available() else "cpu"
133
  torch.cuda.empty_cache()
134
  seed = None
@@ -251,12 +268,6 @@ def edit(init_image, source_prompt, target_prompt, editing_strategy, denoise_str
251
  torch.cuda.empty_cache()
252
  seed = None
253
 
254
- print(f"Inital_t5_device: {t5.hf_module.device}")
255
- print(f"Inital_clip_device: {clip.hf_module.device}")
256
- print(f"Inital_flow_model: {model.img_in.weight.device}")
257
- print(f"Inital_flow_model self.model.img_in: {model.img_in}")
258
- print(f"Inital_flow_model self.model.time_in.out_layer.weight: {model.time_in.out_layer.weight}")
259
-
260
  #----------------------------- 0.1 prepare multi-turn editing -------------------------------------#
261
  info = {}
262
  shape = init_image.shape
@@ -333,7 +344,6 @@ def edit(init_image, source_prompt, target_prompt, editing_strategy, denoise_str
333
  inp_target_2 = None
334
  if not init_image_2 is None:
335
  inp_target_2 = prepare_image(init_image_2)
336
- info['lqr_stop'] = 0.35
337
 
338
  timesteps = get_schedule(opts.num_steps, inp["img"].shape[1], shift=(name != "flux-schnell"))
339
  #timesteps = get_schedule(opts.num_steps, inp["img"].shape[1], shift=False)
@@ -460,6 +470,7 @@ def edit(init_image, source_prompt, target_prompt, editing_strategy, denoise_str
460
 
461
  def on_select(gallery, selected: gr.SelectData):
462
  return gallery[selected.index][0], gallery[selected.index][1]
 
463
 
464
  def on_upload(path, uploaded: gr.EventData):
465
  return path[0][0]
@@ -474,7 +485,7 @@ def create_demo(model_name: str, device: str = "cuda" if torch.cuda.is_available
474
 
475
  # Pre-defined examples
476
  examples = [
477
- ["src/gradio_utils/gradio_examples/000000000011.jpg", "", "a photo of a eagle standing on the branch", ['attn_guidance'], 15, 3.5, 11, 0],
478
  ["src/gradio_utils/gradio_examples/221000000002.jpg", "", "a cat wearing a hat standing on the fence", ['attn_guidance'], 15, 3.5, 11, 0],
479
  ]
480
 
@@ -511,6 +522,7 @@ def create_demo(model_name: str, device: str = "cuda" if torch.cuda.is_available
511
  example_image = gr.Image(label="example Image", visible=False, width=200)
512
 
513
  gallery.select(on_select, gallery, [init_image, source_prompt])
 
514
  gallery.upload(on_upload, gallery, init_image)
515
  example_image.change(on_change, example_image, [gallery, init_image])
516
 
@@ -542,4 +554,4 @@ def create_demo(model_name: str, device: str = "cuda" if torch.cuda.is_available
542
 
543
  demo = create_demo(name, "cuda")
544
  #demo.launch(server_name='0.0.0.0', share=args.share, server_port=args.port)
545
- demo.launch(debug=True)
 
41
  t5 = load_t5(device, max_length=256 if name == "flux-schnell" else 512)
42
  clip = load_clip(device)
43
  model = load_flow_model(name, device="cpu" if offload else torch_device)
44
+ t5.eval()
45
+ clip.eval()
46
+ ae.eval()
47
+ model.eval()
48
+
49
  is_schnell = False
50
  add_sampling_metadata = True
51
 
 
56
  out_root = 'src/gradio_utils/gradio_outputs'
57
  if not os.path.exists(out_root):
58
  os.makedirs(out_root)
59
+ exp_folders = [d for d in os.listdir(out_root) if d.startswith("exp_") and d[4:].isdigit()]
60
+ if exp_folders:
61
+ max_idx = max(int(d[4:]) for d in exp_folders)
62
+ name_dir = f"exp_{max_idx + 1}"
63
+ else:
64
+ name_dir = "exp_0"
65
  output_dir = os.path.join(out_root, name_dir)
66
+
67
  if not os.path.exists(output_dir):
68
  os.makedirs(output_dir)
69
  if not os.path.exists("heatmap"):
 
84
  if os.path.exists("history_gradio/history.safetensors"):
85
  os.remove("history_gradio/history.safetensors")
86
 
87
+ global out_root, output_dir, history_tensors, source_image, instructions
88
  if not os.path.exists(out_root):
89
  os.makedirs(out_root)
90
+ exp_folders = [d for d in os.listdir(out_root) if d.startswith("exp_") and d[4:].isdigit()]
91
+ if exp_folders:
92
+ max_idx = max(int(d[4:]) for d in exp_folders)
93
+ name_dir = f"exp_{max_idx + 1}"
94
+ else:
95
+ name_dir = "exp_0"
96
  output_dir = os.path.join(out_root, name_dir)
97
+
98
  if not os.path.exists(output_dir):
99
  os.makedirs(output_dir)
100
  if not os.path.exists("heatmap"):
 
145
  init_image=None,
146
  image2image_strength=0.0,
147
  ):
148
+ global ae, t5, clip, model, name, is_schnell, output_dir, add_sampling_metadata, offload, history_tensors
149
  device = "cuda" if torch.cuda.is_available() else "cpu"
150
  torch.cuda.empty_cache()
151
  seed = None
 
268
  torch.cuda.empty_cache()
269
  seed = None
270
 
 
 
 
 
 
 
271
  #----------------------------- 0.1 prepare multi-turn editing -------------------------------------#
272
  info = {}
273
  shape = init_image.shape
 
344
  inp_target_2 = None
345
  if not init_image_2 is None:
346
  inp_target_2 = prepare_image(init_image_2)
 
347
 
348
  timesteps = get_schedule(opts.num_steps, inp["img"].shape[1], shift=(name != "flux-schnell"))
349
  #timesteps = get_schedule(opts.num_steps, inp["img"].shape[1], shift=False)
 
470
 
471
  def on_select(gallery, selected: gr.SelectData):
472
  return gallery[selected.index][0], gallery[selected.index][1]
473
+ #return gallery[selected.index][0]
474
 
475
  def on_upload(path, uploaded: gr.EventData):
476
  return path[0][0]
 
485
 
486
  # Pre-defined examples
487
  examples = [
488
+ ["src/gradio_utils/gradio_examples/000000000011.jpg", "", "an eagle standing on the branch", ['attn_guidance'], 15, 3.5, 11, 0],
489
  ["src/gradio_utils/gradio_examples/221000000002.jpg", "", "a cat wearing a hat standing on the fence", ['attn_guidance'], 15, 3.5, 11, 0],
490
  ]
491
 
 
522
  example_image = gr.Image(label="example Image", visible=False, width=200)
523
 
524
  gallery.select(on_select, gallery, [init_image, source_prompt])
525
+ #gallery.select(on_select, gallery, [init_image])
526
  gallery.upload(on_upload, gallery, init_image)
527
  example_image.change(on_change, example_image, [gallery, init_image])
528
 
 
554
 
555
  demo = create_demo(name, "cuda")
556
  #demo.launch(server_name='0.0.0.0', share=args.share, server_port=args.port)
557
+ demo.launch(debug=True)
src/flux/__pycache__/__init__.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/__init__.cpython-310.pyc and b/src/flux/__pycache__/__init__.cpython-310.pyc differ
 
src/flux/__pycache__/_version.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/_version.cpython-310.pyc and b/src/flux/__pycache__/_version.cpython-310.pyc differ
 
src/flux/__pycache__/math.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/math.cpython-310.pyc and b/src/flux/__pycache__/math.cpython-310.pyc differ
 
src/flux/__pycache__/model.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/model.cpython-310.pyc and b/src/flux/__pycache__/model.cpython-310.pyc differ
 
src/flux/__pycache__/sampling.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/sampling.cpython-310.pyc and b/src/flux/__pycache__/sampling.cpython-310.pyc differ
 
src/flux/__pycache__/util.cpython-310.pyc CHANGED
Binary files a/src/flux/__pycache__/util.cpython-310.pyc and b/src/flux/__pycache__/util.cpython-310.pyc differ
 
src/flux/modules/__pycache__/autoencoder.cpython-310.pyc CHANGED
Binary files a/src/flux/modules/__pycache__/autoencoder.cpython-310.pyc and b/src/flux/modules/__pycache__/autoencoder.cpython-310.pyc differ
 
src/flux/modules/__pycache__/conditioner.cpython-310.pyc CHANGED
Binary files a/src/flux/modules/__pycache__/conditioner.cpython-310.pyc and b/src/flux/modules/__pycache__/conditioner.cpython-310.pyc differ
 
src/flux/modules/__pycache__/layers.cpython-310.pyc CHANGED
Binary files a/src/flux/modules/__pycache__/layers.cpython-310.pyc and b/src/flux/modules/__pycache__/layers.cpython-310.pyc differ