Update app.py
Browse files
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 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
# Collect generated visuals
|
| 146 |
visuals = [os.path.join('./figures', f) for f in os.listdir('./figures')
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
| 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:
|