hmgill commited on
Commit
09bce3d
Β·
verified Β·
1 Parent(s): d5ded18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -325,6 +325,8 @@ async def unified_chat_handler(message, history, session_id, current_img_path):
325
  history.append({"role": "user", "content": f"![](file={image_path})\n\n{user_text}"})
326
  history.append({"role": "assistant", "content": "πŸ”„ Starting analysis (Model loading may take a moment)..."})
327
 
 
 
328
  yield history, session_id, image_path, gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), *empty_slider_updates, None, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
329
 
330
  final_result = None
@@ -333,12 +335,16 @@ async def unified_chat_handler(message, history, session_id, current_img_path):
333
  updated_history = result[0].copy()
334
  if files and len(updated_history) > 0:
335
  updated_history[0] = {"role": "user", "content": f"![](file={image_path})\n\n{user_text}"}
336
- yield (updated_history, result[1], image_path, *result[2:], None, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False))
 
 
337
 
338
  if final_result:
339
  updated_history = final_result[0].copy()
340
  if files and len(updated_history) > 0:
341
  updated_history[0] = {"role": "user", "content": f"![](file={image_path})\n\n{user_text}"}
 
 
342
  yield (updated_history, final_result[1], image_path, *final_result[2:], None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=True))
343
  return
344
 
@@ -379,8 +385,8 @@ async def unified_chat_handler(message, history, session_id, current_img_path):
379
  custom_css = """
380
  /* 1. Global Margin Setting */
381
  #main_container {
382
- margin-left: 10% !important;
383
- margin-right: 10% !important;
384
  width: auto !important;
385
  }
386
 
@@ -437,7 +443,7 @@ with gr.Blocks(title="Cellemetry Agent", css=custom_css) as demo:
437
  # Welcome overlay (Visible Initially)
438
  with gr.Column(visible=True, elem_id="welcome-overlay") as welcome_overlay:
439
  gr.HTML(f"""
440
- <div style="display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 780px; padding: 40px; background: #f8f9fa; border-radius: 8px; border: 2px solid #3498db;">
441
  <div style="text-align: center;">
442
  <div style='text-align: center;'>
443
  <img src="https://raw.githubusercontent.com/hmgill/Cellemetry/main/logo.png" alt="Logo" style="height:200px; display: block; margin: 0 auto;">
@@ -466,7 +472,6 @@ with gr.Blocks(title="Cellemetry Agent", css=custom_css) as demo:
466
  """)
467
 
468
  # Results tabs (Hidden Initially)
469
- # FIX: Added bordered-panel class for consistent blue border
470
  with gr.Column(visible=False, elem_classes=["bordered-panel"]) as results_container:
471
  with gr.Tabs() as results_tabs:
472
  with gr.Tab("πŸ” Segmentation"):
 
325
  history.append({"role": "user", "content": f"![](file={image_path})\n\n{user_text}"})
326
  history.append({"role": "assistant", "content": "πŸ”„ Starting analysis (Model loading may take a moment)..."})
327
 
328
+ # YIELD 1: Set initial visibility state ONCE
329
+ # Hide Welcome, Show Loading, Hide Results
330
  yield history, session_id, image_path, gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), *empty_slider_updates, None, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
331
 
332
  final_result = None
 
335
  updated_history = result[0].copy()
336
  if files and len(updated_history) > 0:
337
  updated_history[0] = {"role": "user", "content": f"![](file={image_path})\n\n{user_text}"}
338
+
339
+ # YIELD LOOP: Pass gr.update() for visibility to prevent flickering
340
+ yield (updated_history, result[1], image_path, *result[2:], None, gr.update(), gr.update(), gr.update())
341
 
342
  if final_result:
343
  updated_history = final_result[0].copy()
344
  if files and len(updated_history) > 0:
345
  updated_history[0] = {"role": "user", "content": f"![](file={image_path})\n\n{user_text}"}
346
+
347
+ # YIELD FINAL: Show Results, Hide Loading
348
  yield (updated_history, final_result[1], image_path, *final_result[2:], None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=True))
349
  return
350
 
 
385
  custom_css = """
386
  /* 1. Global Margin Setting */
387
  #main_container {
388
+ margin-left: 20% !important;
389
+ margin-right: 20% !important;
390
  width: auto !important;
391
  }
392
 
 
443
  # Welcome overlay (Visible Initially)
444
  with gr.Column(visible=True, elem_id="welcome-overlay") as welcome_overlay:
445
  gr.HTML(f"""
446
+ <div style="display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 780px; padding: 40px; background: #ffffff; border-radius: 8px; border: 2px solid #3498db;">
447
  <div style="text-align: center;">
448
  <div style='text-align: center;'>
449
  <img src="https://raw.githubusercontent.com/hmgill/Cellemetry/main/logo.png" alt="Logo" style="height:200px; display: block; margin: 0 auto;">
 
472
  """)
473
 
474
  # Results tabs (Hidden Initially)
 
475
  with gr.Column(visible=False, elem_classes=["bordered-panel"]) as results_container:
476
  with gr.Tabs() as results_tabs:
477
  with gr.Tab("πŸ” Segmentation"):