Ali2206 commited on
Commit
ccb72b9
·
verified ·
1 Parent(s): 9d7010c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
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, (dict, list)):
42
- try:
43
- formatted = json.dumps(content, indent=2)
44
- except Exception:
45
- formatted = str(content)
 
 
 
 
 
 
 
46
  else:
47
  formatted = str(content)
48
 
49
- title = f"Answer from: {tool_name}" if tool_name else "Answer"
50
 
51
- return f"""
52
- <details style='border: 1px solid #444; background-color: #1e1e1e; border-radius: 8px; padding: 10px; margin: 10px 0;'>
53
- <summary style='color: #37B6E9; font-weight: 600; font-size: 16px;'>{title}</summary>
54
- <pre style='color: #eee; font-family: Consolas, monospace; padding-top: 10px;'>{formatted}</pre>
55
- </details>
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):