samwell commited on
Commit
86d018b
·
1 Parent(s): 5c75114

Add grounding visualization image display in chat interface

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -65,6 +65,8 @@ agent = Agent(
65
 
66
  print(f"Tools loaded: {len(tools)}")
67
 
 
 
68
  def chat(message, history):
69
  config = {"configurable": {"thread_id": "default"}}
70
 
@@ -81,7 +83,21 @@ def chat(message, history):
81
  {"messages": [("user", message)]},
82
  config=config
83
  )
84
- return response["messages"][-1].content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  demo = gr.ChatInterface(
87
  fn=chat,
 
65
 
66
  print(f"Tools loaded: {len(tools)}")
67
 
68
+ import glob
69
+
70
  def chat(message, history):
71
  config = {"configurable": {"thread_id": "default"}}
72
 
 
83
  {"messages": [("user", message)]},
84
  config=config
85
  )
86
+
87
+ # Extract text response
88
+ assistant_message = response["messages"][-1].content
89
+
90
+ # Check for grounding visualization images
91
+ viz_files = glob.glob("temp/grounding_*.png")
92
+ if viz_files:
93
+ # Get the most recent visualization
94
+ viz_files.sort(key=os.path.getmtime, reverse=True)
95
+ latest_viz = viz_files[0]
96
+
97
+ # Append image reference that Gradio can render
98
+ assistant_message += f"\n\n**Grounding Visualization:**\n\n<img src='/file={latest_viz}' style='max-width: 600px;'/>"
99
+
100
+ return assistant_message
101
 
102
  demo = gr.ChatInterface(
103
  fn=chat,