Update app.py
Browse files
app.py
CHANGED
@@ -38,22 +38,29 @@ question_examples = [
|
|
38 |
|
39 |
# Helper: collapsible format with tool name
|
40 |
def format_collapsible(content, tool_name=None):
|
41 |
-
if isinstance(content,
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
else:
|
47 |
formatted = str(content)
|
48 |
|
49 |
-
title = f"
|
50 |
|
51 |
-
return
|
52 |
-
|
53 |
-
<summary style='
|
54 |
-
<pre style='
|
55 |
-
|
56 |
-
|
57 |
|
58 |
# UI setup
|
59 |
def create_ui(agent):
|
|
|
38 |
|
39 |
# Helper: collapsible format with tool name
|
40 |
def format_collapsible(content, tool_name=None):
|
41 |
+
if isinstance(content, dict) and "results" in content:
|
42 |
+
readable = ""
|
43 |
+
for i, result in enumerate(content["results"], 1):
|
44 |
+
readable += f"Result {i}:\n"
|
45 |
+
for key, value in result.items():
|
46 |
+
key_str = key.replace("openfda.", "").replace("_", " ").capitalize()
|
47 |
+
val_str = ", ".join(value) if isinstance(value, list) else str(value)
|
48 |
+
readable += f"- {key_str}: {val_str}\n"
|
49 |
+
readable += "\n"
|
50 |
+
formatted = readable.strip()
|
51 |
+
elif isinstance(content, (dict, list)):
|
52 |
+
formatted = json.dumps(content, indent=2)
|
53 |
else:
|
54 |
formatted = str(content)
|
55 |
|
56 |
+
title = f"{tool_name} Result" if tool_name else "Answer"
|
57 |
|
58 |
+
return (
|
59 |
+
"<details style='border: 1px solid #aaa; border-radius: 8px; padding: 10px; margin: 12px 0; background-color: #f8f8f8;'>"
|
60 |
+
f"<summary style='font-weight: bold; font-size: 16px; color: #333;'>{title}</summary>"
|
61 |
+
f"<pre style='white-space: pre-wrap; font-family: monospace; color: #222; padding-top: 6px;'>{formatted}</pre>"
|
62 |
+
"</details>"
|
63 |
+
)
|
64 |
|
65 |
# UI setup
|
66 |
def create_ui(agent):
|