remiii25 commited on
Commit
518cde7
·
verified ·
1 Parent(s): 20164f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -8,6 +8,8 @@ import torch.nn.functional as F
8
  import faiss
9
  import cv2
10
  import gradio as gr
 
 
11
  from huggingface_hub import snapshot_download
12
 
13
  # ----------------------------
@@ -327,15 +329,15 @@ def chat_and_render(user_text, display_history, llm_history, view_key, tau_slide
327
  return display_history, llm_history, load_gt_np_for_view(view_key), None, view_key, tau_slider, ""
328
 
329
 
330
- #display_history = display_history + [{"role":"user","content": user_text}]
331
  llm_history = llm_history + [{"role":"user","content": user_text}]
332
 
333
  try:
334
  obj = route_with_groq(llm_history[-6:])
335
  except Exception as e:
336
  msg = f"[Router error] {e}"
337
- #display_history += [{"role":"assistant","content": msg}]
338
- display_history = display_history + [(user_text, assistant_msg)]
339
  llm_history += [{"role":"assistant","content": msg}]
340
  return display_history, llm_history, load_gt_np_for_view(view_key), None, view_key, tau_slider, ""
341
 
@@ -355,8 +357,8 @@ def chat_and_render(user_text, display_history, llm_history, view_key, tau_slide
355
 
356
  if label is None:
357
  assistant_msg = reply or "Which object should I look for?"
358
- #display_history += [{"role":"assistant","content": assistant_msg}]
359
- display_history = display_history + [(user_text, assistant_msg)]
360
  llm_history += [{"role":"assistant","content": assistant_msg}]
361
  return display_history, llm_history, load_gt_np_for_view(view_key), None, view_key, tau_used, ""
362
 
@@ -364,14 +366,14 @@ def chat_and_render(user_text, display_history, llm_history, view_key, tau_slide
364
  gt = load_gt_np_for_view(view_key)
365
  sel = sess.render_selected_rgb_np(label=label, tau=tau_used, frame=view_key, split="train")
366
  assistant_msg = reply or f"Showing {label} (tau={tau_used:.2f})."
367
- #display_history += [{"role":"assistant","content": assistant_msg}]
368
- display_history = display_history + [(user_text, assistant_msg)]
369
  llm_history += [{"role":"assistant","content": assistant_msg}]
370
  return display_history, llm_history, gt, sel, view_key, tau_used, ""
371
  except Exception as e:
372
  assistant_msg = f"[Render error] {e}"
373
- #display_history += [{"role":"assistant","content": assistant_msg}]
374
- display_history = display_history + [(user_text, assistant_msg)]
375
  llm_history += [{"role":"assistant","content": assistant_msg}]
376
  return display_history, llm_history, load_gt_np_for_view(view_key), None, view_key, tau_used, ""
377
 
@@ -388,8 +390,8 @@ with gr.Blocks() as demo:
388
  img_gt = gr.Image(type="numpy", label="Original")
389
  img_sel = gr.Image(type="numpy", label="Selected")
390
 
391
- #chatbot = gr.Chatbot(type="messages", label="Chat")
392
- chatbot = gr.Chatbot(label="Chat")
393
  msg = gr.Textbox(placeholder="Ask: Where is the apple?", label="Message")
394
  send = gr.Button("Send")
395
 
 
8
  import faiss
9
  import cv2
10
  import gradio as gr
11
+ print("Gradio version:", gr.__version__)
12
+
13
  from huggingface_hub import snapshot_download
14
 
15
  # ----------------------------
 
329
  return display_history, llm_history, load_gt_np_for_view(view_key), None, view_key, tau_slider, ""
330
 
331
 
332
+ display_history = display_history + [{"role":"user","content": user_text}]
333
  llm_history = llm_history + [{"role":"user","content": user_text}]
334
 
335
  try:
336
  obj = route_with_groq(llm_history[-6:])
337
  except Exception as e:
338
  msg = f"[Router error] {e}"
339
+ display_history += [{"role":"assistant","content": msg}]
340
+ #display_history = display_history + [(user_text, assistant_msg)]
341
  llm_history += [{"role":"assistant","content": msg}]
342
  return display_history, llm_history, load_gt_np_for_view(view_key), None, view_key, tau_slider, ""
343
 
 
357
 
358
  if label is None:
359
  assistant_msg = reply or "Which object should I look for?"
360
+ display_history += [{"role":"assistant","content": assistant_msg}]
361
+ #display_history = display_history + [(user_text, assistant_msg)]
362
  llm_history += [{"role":"assistant","content": assistant_msg}]
363
  return display_history, llm_history, load_gt_np_for_view(view_key), None, view_key, tau_used, ""
364
 
 
366
  gt = load_gt_np_for_view(view_key)
367
  sel = sess.render_selected_rgb_np(label=label, tau=tau_used, frame=view_key, split="train")
368
  assistant_msg = reply or f"Showing {label} (tau={tau_used:.2f})."
369
+ display_history += [{"role":"assistant","content": assistant_msg}]
370
+ #display_history = display_history + [(user_text, assistant_msg)]
371
  llm_history += [{"role":"assistant","content": assistant_msg}]
372
  return display_history, llm_history, gt, sel, view_key, tau_used, ""
373
  except Exception as e:
374
  assistant_msg = f"[Render error] {e}"
375
+ display_history += [{"role":"assistant","content": assistant_msg}]
376
+ #display_history = display_history + [(user_text, assistant_msg)]
377
  llm_history += [{"role":"assistant","content": assistant_msg}]
378
  return display_history, llm_history, load_gt_np_for_view(view_key), None, view_key, tau_used, ""
379
 
 
390
  img_gt = gr.Image(type="numpy", label="Original")
391
  img_sel = gr.Image(type="numpy", label="Selected")
392
 
393
+ chatbot = gr.Chatbot(type="messages", label="Chat")
394
+ #chatbot = gr.Chatbot(label="Chat")
395
  msg = gr.Textbox(placeholder="Ask: Where is the apple?", label="Message")
396
  send = gr.Button("Send")
397