Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,8 @@ import subprocess
|
|
3 |
import os
|
4 |
import json
|
5 |
import numpy as np
|
6 |
-
import
|
|
|
7 |
from PIL import Image
|
8 |
import time
|
9 |
import io
|
@@ -279,63 +280,150 @@ with right_column:
|
|
279 |
theoretical_max = np.array(data['theoretical_max'])
|
280 |
theoretical_min = np.array(data['theoretical_min'])
|
281 |
|
282 |
-
# Create
|
283 |
-
fig
|
284 |
|
285 |
-
#
|
286 |
-
fig.
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
|
|
|
|
|
|
|
|
|
|
298 |
|
299 |
-
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
-
#
|
309 |
-
|
310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
|
312 |
-
# Add
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
# Adjust layout
|
322 |
-
plt.tight_layout(rect=[0, 0.05, 1, 0.95])
|
323 |
-
|
324 |
-
# Save the plot to a buffer
|
325 |
-
buf = io.BytesIO()
|
326 |
-
plt.savefig(buf, format='png', dpi=100)
|
327 |
-
buf.seek(0)
|
328 |
-
|
329 |
-
# Save to file
|
330 |
-
output_file = os.path.join(output_dir, "eigenvalue_analysis.png")
|
331 |
-
plt.savefig(output_file, format='png', dpi=100)
|
332 |
-
plt.close()
|
333 |
|
334 |
# Clear progress container
|
335 |
progress_container.empty()
|
336 |
|
337 |
-
# Display the
|
338 |
-
st.
|
|
|
|
|
|
|
|
|
339 |
|
340 |
# Provide download button
|
341 |
col1, col2, col3 = st.columns([1, 2, 1])
|
@@ -417,12 +505,127 @@ with right_column:
|
|
417 |
st.error(f"An error occurred: {str(e)}")
|
418 |
|
419 |
else:
|
420 |
-
#
|
421 |
-
|
422 |
-
if os.path.exists(
|
423 |
-
|
424 |
-
|
425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
else:
|
427 |
# Show placeholder
|
428 |
st.info("👈 Set parameters and click 'Generate Analysis' to create a visualization.")
|
|
|
3 |
import os
|
4 |
import json
|
5 |
import numpy as np
|
6 |
+
import plotly.graph_objects as go
|
7 |
+
from plotly.subplots import make_subplots
|
8 |
from PIL import Image
|
9 |
import time
|
10 |
import io
|
|
|
280 |
theoretical_max = np.array(data['theoretical_max'])
|
281 |
theoretical_min = np.array(data['theoretical_min'])
|
282 |
|
283 |
+
# Create an interactive plot using Plotly
|
284 |
+
fig = go.Figure()
|
285 |
|
286 |
+
# Add traces for each line
|
287 |
+
fig.add_trace(go.Scatter(
|
288 |
+
x=beta_values,
|
289 |
+
y=max_eigenvalues,
|
290 |
+
mode='lines+markers',
|
291 |
+
name='Empirical Max Eigenvalue',
|
292 |
+
line=dict(color='rgb(220, 60, 60)', width=3),
|
293 |
+
marker=dict(
|
294 |
+
symbol='circle',
|
295 |
+
size=8,
|
296 |
+
color='rgb(220, 60, 60)',
|
297 |
+
line=dict(color='white', width=1)
|
298 |
+
),
|
299 |
+
hovertemplate='β: %{x:.3f}<br>Value: %{y:.6f}<extra>Empirical Max</extra>'
|
300 |
+
))
|
301 |
|
302 |
+
fig.add_trace(go.Scatter(
|
303 |
+
x=beta_values,
|
304 |
+
y=min_eigenvalues,
|
305 |
+
mode='lines+markers',
|
306 |
+
name='Empirical Min Eigenvalue',
|
307 |
+
line=dict(color='rgb(60, 60, 220)', width=3),
|
308 |
+
marker=dict(
|
309 |
+
symbol='circle',
|
310 |
+
size=8,
|
311 |
+
color='rgb(60, 60, 220)',
|
312 |
+
line=dict(color='white', width=1)
|
313 |
+
),
|
314 |
+
hovertemplate='β: %{x:.3f}<br>Value: %{y:.6f}<extra>Empirical Min</extra>'
|
315 |
+
))
|
316 |
|
317 |
+
fig.add_trace(go.Scatter(
|
318 |
+
x=beta_values,
|
319 |
+
y=theoretical_max,
|
320 |
+
mode='lines+markers',
|
321 |
+
name='Theoretical Max Function',
|
322 |
+
line=dict(color='rgb(30, 180, 30)', width=3),
|
323 |
+
marker=dict(
|
324 |
+
symbol='diamond',
|
325 |
+
size=8,
|
326 |
+
color='rgb(30, 180, 30)',
|
327 |
+
line=dict(color='white', width=1)
|
328 |
+
),
|
329 |
+
hovertemplate='β: %{x:.3f}<br>Value: %{y:.6f}<extra>Theoretical Max</extra>'
|
330 |
+
))
|
331 |
|
332 |
+
fig.add_trace(go.Scatter(
|
333 |
+
x=beta_values,
|
334 |
+
y=theoretical_min,
|
335 |
+
mode='lines+markers',
|
336 |
+
name='Theoretical Min Function',
|
337 |
+
line=dict(color='rgb(180, 30, 180)', width=3),
|
338 |
+
marker=dict(
|
339 |
+
symbol='diamond',
|
340 |
+
size=8,
|
341 |
+
color='rgb(180, 30, 180)',
|
342 |
+
line=dict(color='white', width=1)
|
343 |
+
),
|
344 |
+
hovertemplate='β: %{x:.3f}<br>Value: %{y:.6f}<extra>Theoretical Min</extra>'
|
345 |
+
))
|
346 |
|
347 |
+
# Configure layout for better appearance
|
348 |
+
fig.update_layout(
|
349 |
+
title={
|
350 |
+
'text': f'Eigenvalue Analysis: n={n}, p={p}, a={a}, y={y:.4f}',
|
351 |
+
'font': {'size': 24, 'color': '#1E88E5'},
|
352 |
+
'y': 0.95,
|
353 |
+
'x': 0.5,
|
354 |
+
'xanchor': 'center',
|
355 |
+
'yanchor': 'top'
|
356 |
+
},
|
357 |
+
xaxis={
|
358 |
+
'title': 'β Parameter',
|
359 |
+
'titlefont': {'size': 18, 'color': '#424242'},
|
360 |
+
'tickfont': {'size': 14},
|
361 |
+
'gridcolor': 'rgba(220, 220, 220, 0.5)',
|
362 |
+
'showgrid': True
|
363 |
+
},
|
364 |
+
yaxis={
|
365 |
+
'title': 'Eigenvalues',
|
366 |
+
'titlefont': {'size': 18, 'color': '#424242'},
|
367 |
+
'tickfont': {'size': 14},
|
368 |
+
'gridcolor': 'rgba(220, 220, 220, 0.5)',
|
369 |
+
'showgrid': True
|
370 |
+
},
|
371 |
+
plot_bgcolor='rgba(240, 240, 240, 0.8)',
|
372 |
+
paper_bgcolor='rgba(249, 249, 249, 0.8)',
|
373 |
+
hovermode='closest',
|
374 |
+
legend={
|
375 |
+
'font': {'size': 14},
|
376 |
+
'bgcolor': 'rgba(255, 255, 255, 0.9)',
|
377 |
+
'bordercolor': 'rgba(200, 200, 200, 0.5)',
|
378 |
+
'borderwidth': 1
|
379 |
+
},
|
380 |
+
margin={'l': 60, 'r': 30, 't': 100, 'b': 60},
|
381 |
+
height=600,
|
382 |
+
annotations=[
|
383 |
+
{
|
384 |
+
'text': f"Max Function: max{{k ∈ (0,∞)}} [yβ(a-1)k + (ak+1)((y-1)k-1)]/[(ak+1)(k²+k)]",
|
385 |
+
'xref': 'paper', 'yref': 'paper',
|
386 |
+
'x': 0.02, 'y': 0.02,
|
387 |
+
'showarrow': False,
|
388 |
+
'font': {'size': 12, 'color': 'rgb(30, 180, 30)'},
|
389 |
+
'bgcolor': 'rgba(255, 255, 255, 0.9)',
|
390 |
+
'bordercolor': 'rgb(30, 180, 30)',
|
391 |
+
'borderwidth': 1,
|
392 |
+
'borderpad': 4
|
393 |
+
},
|
394 |
+
{
|
395 |
+
'text': f"Min Function: min{{t ∈ (-1/a,0)}} [yβ(a-1)t + (at+1)((y-1)t-1)]/[(at+1)(t²+t)]",
|
396 |
+
'xref': 'paper', 'yref': 'paper',
|
397 |
+
'x': 0.55, 'y': 0.02,
|
398 |
+
'showarrow': False,
|
399 |
+
'font': {'size': 12, 'color': 'rgb(180, 30, 180)'},
|
400 |
+
'bgcolor': 'rgba(255, 255, 255, 0.9)',
|
401 |
+
'bordercolor': 'rgb(180, 30, 180)',
|
402 |
+
'borderwidth': 1,
|
403 |
+
'borderpad': 4
|
404 |
+
}
|
405 |
+
]
|
406 |
+
)
|
407 |
|
408 |
+
# Add custom modebar buttons
|
409 |
+
fig.update_layout(
|
410 |
+
modebar_add=[
|
411 |
+
'drawline', 'drawopenpath', 'drawclosedpath',
|
412 |
+
'drawcircle', 'drawrect', 'eraseshape'
|
413 |
+
],
|
414 |
+
modebar_remove=['lasso2d', 'select2d'],
|
415 |
+
dragmode='zoom'
|
416 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
417 |
|
418 |
# Clear progress container
|
419 |
progress_container.empty()
|
420 |
|
421 |
+
# Display the interactive plot in Streamlit
|
422 |
+
st.plotly_chart(fig, use_container_width=True)
|
423 |
+
|
424 |
+
# Generate static image for download
|
425 |
+
output_file = os.path.join(output_dir, "eigenvalue_analysis.png")
|
426 |
+
fig.write_image(output_file, scale=2)
|
427 |
|
428 |
# Provide download button
|
429 |
col1, col2, col3 = st.columns([1, 2, 1])
|
|
|
505 |
st.error(f"An error occurred: {str(e)}")
|
506 |
|
507 |
else:
|
508 |
+
# Try to load existing data if available
|
509 |
+
data_file = os.path.join(output_dir, "eigenvalue_data.json")
|
510 |
+
if os.path.exists(data_file):
|
511 |
+
try:
|
512 |
+
with open(data_file, 'r') as f:
|
513 |
+
data = json.load(f)
|
514 |
+
|
515 |
+
# Extract data
|
516 |
+
beta_values = np.array(data['beta_values'])
|
517 |
+
max_eigenvalues = np.array(data['max_eigenvalues'])
|
518 |
+
min_eigenvalues = np.array(data['min_eigenvalues'])
|
519 |
+
theoretical_max = np.array(data['theoretical_max'])
|
520 |
+
theoretical_min = np.array(data['theoretical_min'])
|
521 |
+
|
522 |
+
# Create an interactive plot using Plotly
|
523 |
+
fig = go.Figure()
|
524 |
+
|
525 |
+
# Add traces for each line
|
526 |
+
fig.add_trace(go.Scatter(
|
527 |
+
x=beta_values,
|
528 |
+
y=max_eigenvalues,
|
529 |
+
mode='lines+markers',
|
530 |
+
name='Empirical Max Eigenvalue',
|
531 |
+
line=dict(color='rgb(220, 60, 60)', width=3),
|
532 |
+
marker=dict(
|
533 |
+
symbol='circle',
|
534 |
+
size=8,
|
535 |
+
color='rgb(220, 60, 60)',
|
536 |
+
line=dict(color='white', width=1)
|
537 |
+
),
|
538 |
+
hovertemplate='β: %{x:.3f}<br>Value: %{y:.6f}<extra>Empirical Max</extra>'
|
539 |
+
))
|
540 |
+
|
541 |
+
fig.add_trace(go.Scatter(
|
542 |
+
x=beta_values,
|
543 |
+
y=min_eigenvalues,
|
544 |
+
mode='lines+markers',
|
545 |
+
name='Empirical Min Eigenvalue',
|
546 |
+
line=dict(color='rgb(60, 60, 220)', width=3),
|
547 |
+
marker=dict(
|
548 |
+
symbol='circle',
|
549 |
+
size=8,
|
550 |
+
color='rgb(60, 60, 220)',
|
551 |
+
line=dict(color='white', width=1)
|
552 |
+
),
|
553 |
+
hovertemplate='β: %{x:.3f}<br>Value: %{y:.6f}<extra>Empirical Min</extra>'
|
554 |
+
))
|
555 |
+
|
556 |
+
fig.add_trace(go.Scatter(
|
557 |
+
x=beta_values,
|
558 |
+
y=theoretical_max,
|
559 |
+
mode='lines+markers',
|
560 |
+
name='Theoretical Max Function',
|
561 |
+
line=dict(color='rgb(30, 180, 30)', width=3),
|
562 |
+
marker=dict(
|
563 |
+
symbol='diamond',
|
564 |
+
size=8,
|
565 |
+
color='rgb(30, 180, 30)',
|
566 |
+
line=dict(color='white', width=1)
|
567 |
+
),
|
568 |
+
hovertemplate='β: %{x:.3f}<br>Value: %{y:.6f}<extra>Theoretical Max</extra>'
|
569 |
+
))
|
570 |
+
|
571 |
+
fig.add_trace(go.Scatter(
|
572 |
+
x=beta_values,
|
573 |
+
y=theoretical_min,
|
574 |
+
mode='lines+markers',
|
575 |
+
name='Theoretical Min Function',
|
576 |
+
line=dict(color='rgb(180, 30, 180)', width=3),
|
577 |
+
marker=dict(
|
578 |
+
symbol='diamond',
|
579 |
+
size=8,
|
580 |
+
color='rgb(180, 30, 180)',
|
581 |
+
line=dict(color='white', width=1)
|
582 |
+
),
|
583 |
+
hovertemplate='β: %{x:.3f}<br>Value: %{y:.6f}<extra>Theoretical Min</extra>'
|
584 |
+
))
|
585 |
+
|
586 |
+
# Configure layout for better appearance
|
587 |
+
fig.update_layout(
|
588 |
+
title={
|
589 |
+
'text': f'Eigenvalue Analysis (Previous Result)',
|
590 |
+
'font': {'size': 24, 'color': '#1E88E5'},
|
591 |
+
'y': 0.95,
|
592 |
+
'x': 0.5,
|
593 |
+
'xanchor': 'center',
|
594 |
+
'yanchor': 'top'
|
595 |
+
},
|
596 |
+
xaxis={
|
597 |
+
'title': 'β Parameter',
|
598 |
+
'titlefont': {'size': 18, 'color': '#424242'},
|
599 |
+
'tickfont': {'size': 14},
|
600 |
+
'gridcolor': 'rgba(220, 220, 220, 0.5)',
|
601 |
+
'showgrid': True
|
602 |
+
},
|
603 |
+
yaxis={
|
604 |
+
'title': 'Eigenvalues',
|
605 |
+
'titlefont': {'size': 18, 'color': '#424242'},
|
606 |
+
'tickfont': {'size': 14},
|
607 |
+
'gridcolor': 'rgba(220, 220, 220, 0.5)',
|
608 |
+
'showgrid': True
|
609 |
+
},
|
610 |
+
plot_bgcolor='rgba(240, 240, 240, 0.8)',
|
611 |
+
paper_bgcolor='rgba(249, 249, 249, 0.8)',
|
612 |
+
hovermode='closest',
|
613 |
+
legend={
|
614 |
+
'font': {'size': 14},
|
615 |
+
'bgcolor': 'rgba(255, 255, 255, 0.9)',
|
616 |
+
'bordercolor': 'rgba(200, 200, 200, 0.5)',
|
617 |
+
'borderwidth': 1
|
618 |
+
},
|
619 |
+
margin={'l': 60, 'r': 30, 't': 100, 'b': 60},
|
620 |
+
height=600
|
621 |
+
)
|
622 |
+
|
623 |
+
# Display the interactive plot in Streamlit
|
624 |
+
st.plotly_chart(fig, use_container_width=True)
|
625 |
+
st.info("This is the previous analysis result. Adjust parameters and click 'Generate Analysis' to create a new visualization.")
|
626 |
+
|
627 |
+
except Exception as e:
|
628 |
+
st.info("👈 Set parameters and click 'Generate Analysis' to create a visualization.")
|
629 |
else:
|
630 |
# Show placeholder
|
631 |
st.info("👈 Set parameters and click 'Generate Analysis' to create a visualization.")
|