pavanmutha commited on
Commit
cac331b
·
verified ·
1 Parent(s): 5e10121

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -23
app.py CHANGED
@@ -4,6 +4,8 @@ from huggingface_hub import login
4
  import os
5
  import shutil
6
  import wandb
 
 
7
 
8
  from huggingface_hub import login
9
 
@@ -77,6 +79,14 @@ def format_insights(insights, visuals):
77
  return '\n'.join(items)
78
 
79
  def analyze_data(csv_file, additional_notes=""):
 
 
 
 
 
 
 
 
80
  # Clear previous figures
81
  if os.path.exists('./figures'):
82
  shutil.rmtree('./figures')
@@ -121,30 +131,31 @@ def analyze_data(csv_file, additional_notes=""):
121
  }
122
  )
123
 
124
- # 🚨 Log analysis results to W&B
125
- try:
126
- if isinstance(analysis_result, dict):
127
- # Log metrics from dictionary structure
128
- wandb.log({
129
- "observations": analysis_result.get('observations', {}),
130
- "insights": analysis_result.get('insights', {}),
131
- "num_visuals": len(visuals)
132
- })
133
- else:
134
- # Log raw output as artifact
135
- wandb.log_artifact(
136
- wandb.Artifact(
137
- "raw_analysis_output",
138
- type="analysis_results",
139
- description=analysis_result
140
- )
141
- )
142
- except Exception as e:
143
- print(f"Error logging to W&B: {e}")
144
-
145
- # Collect generated visuals
146
  visuals = [os.path.join('./figures', f) for f in os.listdir('./figures')
147
- if f.endswith(('.png', '.jpg', '.jpeg'))]
 
 
 
148
 
149
  # 🚨 Log visualizations to W&B
150
  if visuals:
 
4
  import os
5
  import shutil
6
  import wandb
7
+ import time
8
+ import psutil
9
 
10
  from huggingface_hub import login
11
 
 
79
  return '\n'.join(items)
80
 
81
  def analyze_data(csv_file, additional_notes=""):
82
+
83
+ # Start timing
84
+ start_time = time.time()
85
+
86
+ # Get initial memory usage
87
+ process = psutil.Process(os.getpid())
88
+ initial_memory = process.memory_info().rss / 1024 ** 2 # Convert to MB
89
+
90
  # Clear previous figures
91
  if os.path.exists('./figures'):
92
  shutil.rmtree('./figures')
 
131
  }
132
  )
133
 
134
+ # Measure execution time and memory usage
135
+ execution_time = time.time() - start_time
136
+ final_memory = process.memory_info().rss / 1024 ** 2 # Convert to MB
137
+ memory_usage = final_memory - initial_memory # Calculate memory consumed
138
+
139
+ # 🚨 Log Performance Metrics
140
+ wandb.log({
141
+ "execution_time_sec": execution_time,
142
+ "memory_usage_mb": memory_usage
143
+ })
144
+
145
+ # Log analysis results to W&B
146
+ if isinstance(analysis_result, dict):
147
+ wandb.log({
148
+ "observations": analysis_result.get('observations', {}),
149
+ "insights": analysis_result.get('insights', {}),
150
+ "num_visuals": len(os.listdir('./figures')) # Ensure visuals are counted
151
+ })
152
+
153
+ # Log generated visualizations
 
 
154
  visuals = [os.path.join('./figures', f) for f in os.listdir('./figures')
155
+ if f.endswith(('.png', '.jpg', '.jpeg'))]
156
+ for viz in visuals:
157
+ wandb.log({os.path.basename(viz): wandb.Image(viz)})
158
+
159
 
160
  # 🚨 Log visualizations to W&B
161
  if visuals: