Spaces:
Running
Running
Upload app_space_wow.py
Browse files- app_space_wow.py +86 -15
app_space_wow.py
CHANGED
|
@@ -151,28 +151,99 @@ def run_pipeline(scenario_key: str):
|
|
| 151 |
buf1.seek(0)
|
| 152 |
signal_img = mpimg.imread(buf1)
|
| 153 |
|
| 154 |
-
# Energy bar chart
|
| 155 |
-
fig2
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
compute = [100, gating_meta.get("ratio", 1.0) * 100]
|
| 158 |
colors = ['#e74c3c', '#2ecc71']
|
| 159 |
|
| 160 |
-
bars =
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
for bar, val in zip(bars, compute):
|
| 165 |
-
|
| 166 |
-
f'{val:.1f}%', va='center', fontsize=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
bbox=dict(boxstyle='round,pad=0.8', facecolor='#
|
|
|
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
fig2.tight_layout()
|
| 176 |
|
| 177 |
buf2 = io.BytesIO()
|
| 178 |
fig2.savefig(buf2, format='png', dpi=150, bbox_inches='tight')
|
|
|
|
| 151 |
buf1.seek(0)
|
| 152 |
signal_img = mpimg.imread(buf1)
|
| 153 |
|
| 154 |
+
# Energy bar chart - Enhanced version
|
| 155 |
+
fig2 = plt.figure(figsize=(12, 7))
|
| 156 |
+
gs = fig2.add_gridspec(2, 2, height_ratios=[2, 1], hspace=0.4, wspace=0.3)
|
| 157 |
+
|
| 158 |
+
# Main comparison chart
|
| 159 |
+
ax1 = fig2.add_subplot(gs[0, :])
|
| 160 |
+
categories = ['Baseline\n(Traditional ML)', 'Sundew\n(Neurosymbolic)']
|
| 161 |
compute = [100, gating_meta.get("ratio", 1.0) * 100]
|
| 162 |
colors = ['#e74c3c', '#2ecc71']
|
| 163 |
|
| 164 |
+
bars = ax1.barh(categories, compute, color=colors, edgecolor='white', linewidth=2, height=0.6)
|
| 165 |
+
|
| 166 |
+
# Add gradient-like effect with alpha
|
| 167 |
+
for bar, color in zip(bars, colors):
|
| 168 |
+
bar.set_alpha(0.85)
|
| 169 |
|
| 170 |
+
ax1.set_xlabel('Computational Load (%)', fontsize=13, fontweight='bold', color='#2c3e50')
|
| 171 |
+
ax1.set_xlim(0, 115)
|
| 172 |
+
ax1.set_facecolor('#f8f9fa')
|
| 173 |
+
|
| 174 |
+
# Value labels on bars
|
| 175 |
for bar, val in zip(bars, compute):
|
| 176 |
+
ax1.text(val + 1.5, bar.get_y() + bar.get_height()/2,
|
| 177 |
+
f'{val:.1f}%', va='center', fontsize=14, fontweight='bold', color='#2c3e50')
|
| 178 |
+
|
| 179 |
+
# Dramatic savings callout
|
| 180 |
+
ax1.text(57, 1.75, f'{energy_saved:.1f}%',
|
| 181 |
+
ha='center', fontsize=32, fontweight='bold', color='#27ae60')
|
| 182 |
+
ax1.text(57, 1.5, 'ENERGY SAVED',
|
| 183 |
+
ha='center', fontsize=11, fontweight='bold', color='#27ae60', alpha=0.8)
|
| 184 |
+
|
| 185 |
+
# Add arrow showing reduction
|
| 186 |
+
ax1.annotate('', xy=(compute[1], 0.5), xytext=(compute[0], 0.5),
|
| 187 |
+
arrowprops=dict(arrowstyle='->', lw=3, color='#f39c12', alpha=0.7))
|
| 188 |
+
|
| 189 |
+
ax1.set_title('Computational Efficiency Comparison', fontsize=15, fontweight='bold',
|
| 190 |
+
pad=15, color='#2c3e50')
|
| 191 |
+
ax1.spines['top'].set_visible(False)
|
| 192 |
+
ax1.spines['right'].set_visible(False)
|
| 193 |
+
ax1.spines['left'].set_linewidth(1.5)
|
| 194 |
+
ax1.spines['bottom'].set_linewidth(1.5)
|
| 195 |
+
|
| 196 |
+
# Bottom left - Battery life impact
|
| 197 |
+
ax2 = fig2.add_subplot(gs[1, 0])
|
| 198 |
+
battery_baseline = 24 # hours
|
| 199 |
+
battery_sundew = battery_baseline / gating_meta.get("ratio", 1.0)
|
| 200 |
+
battery_data = [battery_baseline, battery_sundew]
|
| 201 |
+
battery_colors = ['#e74c3c', '#2ecc71']
|
| 202 |
+
|
| 203 |
+
bars2 = ax2.bar(['Baseline', 'Sundew'], battery_data, color=battery_colors,
|
| 204 |
+
edgecolor='white', linewidth=2, alpha=0.85)
|
| 205 |
+
ax2.set_ylabel('Battery Life (hours)', fontsize=11, fontweight='bold')
|
| 206 |
+
ax2.set_ylim(0, max(battery_data) * 1.2)
|
| 207 |
+
ax2.set_title('Battery Life Extension', fontsize=12, fontweight='bold', color='#2c3e50')
|
| 208 |
+
|
| 209 |
+
for bar, val in zip(bars2, battery_data):
|
| 210 |
+
height = bar.get_height()
|
| 211 |
+
ax2.text(bar.get_x() + bar.get_width()/2, height + 5,
|
| 212 |
+
f'{val:.0f}h', ha='center', fontsize=11, fontweight='bold')
|
| 213 |
+
|
| 214 |
+
ax2.set_facecolor('#f8f9fa')
|
| 215 |
+
ax2.spines['top'].set_visible(False)
|
| 216 |
+
ax2.spines['right'].set_visible(False)
|
| 217 |
+
|
| 218 |
+
# Bottom right - Cost & environmental impact
|
| 219 |
+
ax3 = fig2.add_subplot(gs[1, 1])
|
| 220 |
+
ax3.axis('off')
|
| 221 |
+
ax3.set_facecolor('#f8f9fa')
|
| 222 |
+
|
| 223 |
+
# Impact metrics
|
| 224 |
+
daily_savings_kwh = 0.024 * (energy_saved / 100) # Assume 24Wh baseline daily consumption
|
| 225 |
+
annual_co2_kg = daily_savings_kwh * 365 * 0.5 # ~0.5 kg CO2 per kWh
|
| 226 |
+
|
| 227 |
+
impact_text = f"""
|
| 228 |
+
Impact per Device (Annual):
|
| 229 |
+
|
| 230 |
+
Energy Saved: {daily_savings_kwh * 365:.1f} kWh
|
| 231 |
+
CO2 Reduced: {annual_co2_kg:.1f} kg
|
| 232 |
+
Cost Savings: ${daily_savings_kwh * 365 * 0.12:.2f}
|
| 233 |
+
|
| 234 |
+
Scaling to 10,000 devices:
|
| 235 |
+
Energy: {daily_savings_kwh * 365 * 10000 / 1000:.1f} MWh/year
|
| 236 |
+
CO2: {annual_co2_kg * 10000 / 1000:.1f} tonnes/year
|
| 237 |
+
"""
|
| 238 |
|
| 239 |
+
ax3.text(0.1, 0.95, impact_text.strip(),
|
| 240 |
+
fontsize=10, verticalalignment='top', fontfamily='monospace',
|
| 241 |
+
bbox=dict(boxstyle='round,pad=0.8', facecolor='#fff3cd',
|
| 242 |
+
edgecolor='#f39c12', linewidth=2, alpha=0.9))
|
| 243 |
|
| 244 |
+
fig2.patch.set_facecolor('white')
|
| 245 |
+
fig2.suptitle('Sundew Energy Efficiency Analysis', fontsize=16, fontweight='bold',
|
| 246 |
+
y=0.98, color='#2c3e50')
|
|
|
|
| 247 |
|
| 248 |
buf2 = io.BytesIO()
|
| 249 |
fig2.savefig(buf2, format='png', dpi=150, bbox_inches='tight')
|