Nandha2017 commited on
Commit
2c7fc4c
·
verified ·
1 Parent(s): ceeb6a1

Add live status updates: GPU allocated / generating / done

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -76,10 +76,12 @@ def run_tryon(
76
  num_steps: int,
77
  guidance_scale: float,
78
  seed: int,
79
- ) -> tuple:
80
  if person_image is None or garment_image is None:
81
  raise gr.Error("Please upload both a person photo and a garment image.")
82
 
 
 
83
  pipe = _get_pipe()
84
 
85
  person = _fit_to_square(person_image)
@@ -89,6 +91,8 @@ def run_tryon(
89
  rng = torch.Generator(device="cuda")
90
  rng.manual_seed(int(seed) if seed != -1 else torch.randint(0, 2**32, (1,)).item())
91
 
 
 
92
  result = pipe(
93
  image=person,
94
  mask_image=mask,
@@ -106,7 +110,7 @@ def run_tryon(
106
  img.save(path, format="PNG")
107
  saved_paths.append(path)
108
 
109
- return output_images, saved_paths
110
 
111
  # ---------------------------------------------------------------------------
112
  # Gradio UI
@@ -137,6 +141,7 @@ with gr.Blocks(title="Virtual Try-On", theme=gr.themes.Soft()) as demo:
137
  try_btn = gr.Button("👗 Try On", variant="primary", size="lg")
138
 
139
  with gr.Column():
 
140
  output_gallery = gr.Gallery(label="Result", columns=1, height=380)
141
  output_files = gr.File(
142
  label="⬇ Download to your device",
@@ -147,7 +152,7 @@ with gr.Blocks(title="Virtual Try-On", theme=gr.themes.Soft()) as demo:
147
  try_btn.click(
148
  fn=run_tryon,
149
  inputs=[person_input, garment_input, cloth_type, num_steps, guidance, seed_input],
150
- outputs=[output_gallery, output_files],
151
  )
152
 
153
  gr.Markdown(
 
76
  num_steps: int,
77
  guidance_scale: float,
78
  seed: int,
79
+ ):
80
  if person_image is None or garment_image is None:
81
  raise gr.Error("Please upload both a person photo and a garment image.")
82
 
83
+ yield [], [], "⏳ GPU allocated — loading model (first run: ~3 min download)…"
84
+
85
  pipe = _get_pipe()
86
 
87
  person = _fit_to_square(person_image)
 
91
  rng = torch.Generator(device="cuda")
92
  rng.manual_seed(int(seed) if seed != -1 else torch.randint(0, 2**32, (1,)).item())
93
 
94
+ yield [], [], f"🎨 Running {num_steps} diffusion steps…"
95
+
96
  result = pipe(
97
  image=person,
98
  mask_image=mask,
 
110
  img.save(path, format="PNG")
111
  saved_paths.append(path)
112
 
113
+ yield output_images, saved_paths, "✅ Done! Download your result below."
114
 
115
  # ---------------------------------------------------------------------------
116
  # Gradio UI
 
141
  try_btn = gr.Button("👗 Try On", variant="primary", size="lg")
142
 
143
  with gr.Column():
144
+ status_text = gr.Textbox(label="Status", value="Ready", interactive=False, max_lines=1)
145
  output_gallery = gr.Gallery(label="Result", columns=1, height=380)
146
  output_files = gr.File(
147
  label="⬇ Download to your device",
 
152
  try_btn.click(
153
  fn=run_tryon,
154
  inputs=[person_input, garment_input, cloth_type, num_steps, guidance, seed_input],
155
+ outputs=[output_gallery, output_files, status_text],
156
  )
157
 
158
  gr.Markdown(