pavanmutha commited on
Commit
d3977ee
·
verified ·
1 Parent(s): 48a7c51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -103,18 +103,31 @@ def format_observations(observations):
103
  ])
104
 
105
  def format_insights(insights, visuals):
 
 
 
 
 
 
 
 
 
106
  return '\n'.join([
107
  f"""
108
  <div style="margin: 20px 0; padding: 20px; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">
109
  <div style="display: flex; align-items: center; gap: 10px;">
110
  <div style="background: #2B547E; color: white; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;">{idx+1}</div>
111
- <p style="margin: 0; font-size: 16px;">{insight}</p>
 
 
 
112
  </div>
113
  {f'<img src="/file={visuals[idx]}" style="max-width: 100%; height: auto; margin-top: 10px; border-radius: 6px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">' if idx < len(visuals) else ''}
114
  </div>
115
- """ for idx, (key, insight) in enumerate(insights.items())
116
  ])
117
 
 
118
  def analyze_data(csv_file, additional_notes=""):
119
  start_time = time.time()
120
  process = psutil.Process(os.getpid())
 
103
  ])
104
 
105
  def format_insights(insights, visuals):
106
+ if isinstance(insights, dict):
107
+ # Old format (dict of key: text)
108
+ insight_items = list(insights.items())
109
+ elif isinstance(insights, list):
110
+ # New format (list of dicts with "insight" and optional "category")
111
+ insight_items = [(item.get("category", f"Insight {idx+1}"), item["insight"]) for idx, item in enumerate(insights)]
112
+ else:
113
+ return "<p>No insights available or incorrect format.</p>"
114
+
115
  return '\n'.join([
116
  f"""
117
  <div style="margin: 20px 0; padding: 20px; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">
118
  <div style="display: flex; align-items: center; gap: 10px;">
119
  <div style="background: #2B547E; color: white; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;">{idx+1}</div>
120
+ <div>
121
+ <h4 style="margin: 0; color: #2B547E;">{title}</h4>
122
+ <p style="margin: 5px 0 0 0; font-size: 16px;">{insight}</p>
123
+ </div>
124
  </div>
125
  {f'<img src="/file={visuals[idx]}" style="max-width: 100%; height: auto; margin-top: 10px; border-radius: 6px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">' if idx < len(visuals) else ''}
126
  </div>
127
+ """ for idx, (title, insight) in enumerate(insight_items)
128
  ])
129
 
130
+
131
  def analyze_data(csv_file, additional_notes=""):
132
  start_time = time.time()
133
  process = psutil.Process(os.getpid())