Spaces:
Running
Running
Abid Ali Awan
commited on
Commit
ยท
23ecbc0
1
Parent(s):
049b708
Refactor UIHandler to enhance collapsible message formatting and improve clarity in tool execution and parameter extraction updates. Update RegRadarAgent report sections for better organization and remove unnecessary markdown artifacts.
Browse files- agents/reg_radar.py +4 -12
- agents/ui_handler.py +53 -48
- images/avatar.png +2 -2
agents/reg_radar.py
CHANGED
@@ -178,26 +178,18 @@ class RegRadarAgent:
|
|
178 |
|
179 |
## ๐๏ธ Executive Summary
|
180 |
(2-3 sentences overview)
|
181 |
-
|
182 |
-
---
|
183 |
-
|
184 |
## ๐ Key Findings
|
185 |
โข Finding 1
|
186 |
โข Finding 2
|
187 |
โข Finding 3
|
188 |
-
|
189 |
-
---
|
190 |
-
|
191 |
## ๐ก๏ธ Compliance Requirements
|
192 |
- List main requirements with priorities
|
193 |
-
|
194 |
-
---
|
195 |
-
|
196 |
## โ
Action Items
|
197 |
- Specific actions with suggested timelines
|
198 |
-
|
199 |
-
---
|
200 |
-
|
201 |
## ๐ Resources
|
202 |
- Links and references
|
203 |
|
|
|
178 |
|
179 |
## ๐๏ธ Executive Summary
|
180 |
(2-3 sentences overview)
|
181 |
+
|
|
|
|
|
182 |
## ๐ Key Findings
|
183 |
โข Finding 1
|
184 |
โข Finding 2
|
185 |
โข Finding 3
|
186 |
+
|
|
|
|
|
187 |
## ๐ก๏ธ Compliance Requirements
|
188 |
- List main requirements with priorities
|
189 |
+
|
|
|
|
|
190 |
## โ
Action Items
|
191 |
- Specific actions with suggested timelines
|
192 |
+
|
|
|
|
|
193 |
## ๐ Resources
|
194 |
- Links and references
|
195 |
|
agents/ui_handler.py
CHANGED
@@ -70,31 +70,46 @@ class UIHandler:
|
|
70 |
# Show tool detection
|
71 |
tool_key, tool_name = self.agent.determine_intended_tool(message)
|
72 |
|
73 |
-
# Initial processing message with tool info
|
74 |
-
status_msg =
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
yield history, "", gr.update(interactive=False), user_id_state
|
77 |
|
78 |
# Extract parameters and process query
|
79 |
params = self.agent.extract_parameters(message)
|
80 |
|
81 |
-
# Clear status and show parameter extraction
|
82 |
history.pop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
# Show tool execution steps
|
85 |
tool_status = f"""
|
86 |
-
|
87 |
-
|
88 |
-
๐ **Parameters Extracted:**
|
89 |
-
- Industry: {params["industry"]}
|
90 |
-
- Region: {params["region"]}
|
91 |
-
- Keywords: {params["keywords"]}
|
92 |
-
|
93 |
-
๐ **Executing {tool_name}...**
|
94 |
-
|
95 |
โณ _This process may take 40-90 seconds depending on the number of webpages being crawled._
|
96 |
"""
|
97 |
-
history.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
yield history, "", gr.update(interactive=False), user_id_state
|
99 |
|
100 |
# Process the regulatory query
|
@@ -102,27 +117,31 @@ class UIHandler:
|
|
102 |
crawl_results = results["crawl_results"]
|
103 |
memory_results = results["memory_results"]
|
104 |
|
105 |
-
# Update with results count
|
106 |
-
history[-1] = ChatMessage(
|
107 |
-
role="assistant",
|
108 |
-
content=tool_status
|
109 |
-
+ f"\n\nโ
**Found {crawl_results['total_found']} regulatory updates**",
|
110 |
-
)
|
111 |
-
yield history, "", gr.update(interactive=False), user_id_state
|
112 |
-
|
113 |
# Show collapsible raw results
|
114 |
if crawl_results["results"]:
|
115 |
collapsible_results = self._format_crawl_results(crawl_results["results"])
|
116 |
-
history.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
yield history, "", gr.update(interactive=False), user_id_state
|
118 |
|
119 |
# Display memory results if available
|
120 |
if memory_results:
|
121 |
memory_msg = self._format_memory_results(memory_results)
|
122 |
-
history.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
yield history, "", gr.update(interactive=False), user_id_state
|
124 |
|
125 |
-
# Generate final analysis
|
126 |
history.append(
|
127 |
ChatMessage(
|
128 |
role="assistant", content="๐ **Generating Compliance Report...**"
|
@@ -141,12 +160,11 @@ class UIHandler:
|
|
141 |
history[-1] = ChatMessage(role="assistant", content=streaming_content)
|
142 |
yield history, "", gr.update(interactive=False), user_id_state
|
143 |
|
144 |
-
# Show completion time
|
145 |
elapsed = time.time() - start_time
|
146 |
-
history
|
147 |
-
|
148 |
-
|
149 |
-
)
|
150 |
)
|
151 |
# Re-enable input box at the end
|
152 |
yield history, "", gr.update(interactive=True), user_id_state
|
@@ -176,16 +194,10 @@ class UIHandler:
|
|
176 |
- URL: {url}
|
177 |
""")
|
178 |
if results_display:
|
179 |
-
|
180 |
-
|
181 |
-
<summary><strong>๐๏ธ Raw Regulatory Data</strong> - Click to expand</summary>
|
182 |
-
|
183 |
-
{"".join(results_display)}
|
184 |
-
|
185 |
-
</details>
|
186 |
-
"""
|
187 |
else:
|
188 |
-
collapsible_results = "
|
189 |
return collapsible_results
|
190 |
|
191 |
def _format_memory_results(self, memory_results):
|
@@ -195,14 +207,7 @@ class UIHandler:
|
|
195 |
for i, mem in enumerate(top_memories, 1):
|
196 |
memory_text = mem.get("memory", "N/A")
|
197 |
memory_details += f"\n**{i}. Memory:** {memory_text[:300]}...\n"
|
198 |
-
memory_msg = f""
|
199 |
-
<details>
|
200 |
-
<summary><strong>๐พ Related Past Queries</strong> - Click to expand</summary>
|
201 |
-
|
202 |
-
Found {len(memory_results)} similar past queries in memory. Top 3 shown below:
|
203 |
-
{memory_details}
|
204 |
-
</details>
|
205 |
-
"""
|
206 |
return memory_msg
|
207 |
|
208 |
def delayed_clear(self, user_id_state):
|
|
|
70 |
# Show tool detection
|
71 |
tool_key, tool_name = self.agent.determine_intended_tool(message)
|
72 |
|
73 |
+
# Initial processing message with tool info (collapsible)
|
74 |
+
status_msg = (
|
75 |
+
f"Using **{tool_name}** to analyze your query (estimated 10-20 seconds)..."
|
76 |
+
)
|
77 |
+
history.append(
|
78 |
+
ChatMessage(
|
79 |
+
role="assistant",
|
80 |
+
content=status_msg,
|
81 |
+
metadata={"title": f"๐ ๏ธ Tool Selected: {tool_name}"},
|
82 |
+
)
|
83 |
+
)
|
84 |
yield history, "", gr.update(interactive=False), user_id_state
|
85 |
|
86 |
# Extract parameters and process query
|
87 |
params = self.agent.extract_parameters(message)
|
88 |
|
89 |
+
# Clear status and show parameter extraction (collapsible)
|
90 |
history.pop()
|
91 |
+
param_msg = f"- Industry: {params['industry']}\n- Region: {params['region']}\n- Keywords: {params['keywords']}"
|
92 |
+
history.append(
|
93 |
+
ChatMessage(
|
94 |
+
role="assistant",
|
95 |
+
content=param_msg,
|
96 |
+
metadata={"title": "๐Parameter Extraction"},
|
97 |
+
)
|
98 |
+
)
|
99 |
+
yield history, "", gr.update(interactive=False), user_id_state
|
100 |
|
101 |
+
# Show tool execution steps (collapsible)
|
102 |
tool_status = f"""
|
103 |
+
**Executing {tool_name}...**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
โณ _This process may take 40-90 seconds depending on the number of webpages being crawled._
|
105 |
"""
|
106 |
+
history.append(
|
107 |
+
ChatMessage(
|
108 |
+
role="assistant",
|
109 |
+
content=tool_status,
|
110 |
+
metadata={"title": "๐ข Tool Execution Status"},
|
111 |
+
)
|
112 |
+
)
|
113 |
yield history, "", gr.update(interactive=False), user_id_state
|
114 |
|
115 |
# Process the regulatory query
|
|
|
117 |
crawl_results = results["crawl_results"]
|
118 |
memory_results = results["memory_results"]
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
# Show collapsible raw results
|
121 |
if crawl_results["results"]:
|
122 |
collapsible_results = self._format_crawl_results(crawl_results["results"])
|
123 |
+
history.append(
|
124 |
+
ChatMessage(
|
125 |
+
role="assistant",
|
126 |
+
content=collapsible_results,
|
127 |
+
metadata={"title": "๐ Raw Regulatory Data", "status": "done"},
|
128 |
+
)
|
129 |
+
)
|
130 |
yield history, "", gr.update(interactive=False), user_id_state
|
131 |
|
132 |
# Display memory results if available
|
133 |
if memory_results:
|
134 |
memory_msg = self._format_memory_results(memory_results)
|
135 |
+
history.append(
|
136 |
+
ChatMessage(
|
137 |
+
role="assistant",
|
138 |
+
content=memory_msg,
|
139 |
+
metadata={"title": "๐พ Past Memories", "status": "done"},
|
140 |
+
)
|
141 |
+
)
|
142 |
yield history, "", gr.update(interactive=False), user_id_state
|
143 |
|
144 |
+
# Generate final analysis (no metadata, standard message)
|
145 |
history.append(
|
146 |
ChatMessage(
|
147 |
role="assistant", content="๐ **Generating Compliance Report...**"
|
|
|
160 |
history[-1] = ChatMessage(role="assistant", content=streaming_content)
|
161 |
yield history, "", gr.update(interactive=False), user_id_state
|
162 |
|
163 |
+
# Show completion time appended to the final report (no metadata)
|
164 |
elapsed = time.time() - start_time
|
165 |
+
history[-1] = ChatMessage(
|
166 |
+
role="assistant",
|
167 |
+
content=streaming_content + f"\n\nโจ Analysis complete ({elapsed:.1f}s).",
|
|
|
168 |
)
|
169 |
# Re-enable input box at the end
|
170 |
yield history, "", gr.update(interactive=True), user_id_state
|
|
|
194 |
- URL: {url}
|
195 |
""")
|
196 |
if results_display:
|
197 |
+
# Only return the content, let Gradio's metadata title handle the dropdown
|
198 |
+
collapsible_results = "\n".join(results_display)
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
else:
|
200 |
+
collapsible_results = "No unique regulatory updates found."
|
201 |
return collapsible_results
|
202 |
|
203 |
def _format_memory_results(self, memory_results):
|
|
|
207 |
for i, mem in enumerate(top_memories, 1):
|
208 |
memory_text = mem.get("memory", "N/A")
|
209 |
memory_details += f"\n**{i}. Memory:** {memory_text[:300]}...\n"
|
210 |
+
memory_msg = f"Found {len(memory_results)} similar past queries in memory. \nTop 3 shown below:\n{memory_details}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
return memory_msg
|
212 |
|
213 |
def delayed_clear(self, user_id_state):
|
images/avatar.png
CHANGED
![]() |
Git LFS Details
|
![]() |
Git LFS Details
|