Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import subprocess
|
|
| 3 |
import os
|
| 4 |
from PIL import Image
|
| 5 |
import time
|
|
|
|
| 6 |
|
| 7 |
# Set page config
|
| 8 |
st.set_page_config(
|
|
@@ -19,8 +20,10 @@ Adjust the parameters below to generate a plot showing the relationship between
|
|
| 19 |
and theoretical eigenvalues.
|
| 20 |
""")
|
| 21 |
|
| 22 |
-
# Create output directory
|
| 23 |
-
os.
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Input parameters sidebar
|
| 26 |
st.sidebar.header("Parameters")
|
|
@@ -40,7 +43,7 @@ if st.sidebar.button("Generate Plot", type="primary"):
|
|
| 40 |
# Show progress
|
| 41 |
with st.spinner("Generating eigenvalue analysis plot... This may take a few moments."):
|
| 42 |
# Run the C++ executable with the parameters
|
| 43 |
-
output_file = "
|
| 44 |
|
| 45 |
# Delete previous output if exists
|
| 46 |
if os.path.exists(output_file):
|
|
@@ -48,7 +51,10 @@ if st.sidebar.button("Generate Plot", type="primary"):
|
|
| 48 |
|
| 49 |
# Execute the C++ program
|
| 50 |
try:
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
process = subprocess.Popen(
|
| 53 |
cmd,
|
| 54 |
stdout=subprocess.PIPE,
|
|
@@ -96,13 +102,14 @@ if st.sidebar.button("Generate Plot", type="primary"):
|
|
| 96 |
except Exception as e:
|
| 97 |
st.error(f"An error occurred: {str(e)}")
|
| 98 |
|
| 99 |
-
# Show example plot on startup
|
| 100 |
-
|
|
|
|
| 101 |
st.info("π Set parameters and click 'Generate Plot' to create a visualization.")
|
| 102 |
else:
|
| 103 |
# Show the most recent plot by default
|
| 104 |
st.subheader("Current Plot")
|
| 105 |
-
img = Image.open(
|
| 106 |
st.image(img, use_column_width=True)
|
| 107 |
|
| 108 |
# Add information about the analysis
|
|
|
|
| 3 |
import os
|
| 4 |
from PIL import Image
|
| 5 |
import time
|
| 6 |
+
import pathlib
|
| 7 |
|
| 8 |
# Set page config
|
| 9 |
st.set_page_config(
|
|
|
|
| 20 |
and theoretical eigenvalues.
|
| 21 |
""")
|
| 22 |
|
| 23 |
+
# Create output directory in the current working directory
|
| 24 |
+
current_dir = os.getcwd()
|
| 25 |
+
output_dir = os.path.join(current_dir, "output")
|
| 26 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 27 |
|
| 28 |
# Input parameters sidebar
|
| 29 |
st.sidebar.header("Parameters")
|
|
|
|
| 43 |
# Show progress
|
| 44 |
with st.spinner("Generating eigenvalue analysis plot... This may take a few moments."):
|
| 45 |
# Run the C++ executable with the parameters
|
| 46 |
+
output_file = os.path.join(output_dir, "eigenvalue_analysis.png")
|
| 47 |
|
| 48 |
# Delete previous output if exists
|
| 49 |
if os.path.exists(output_file):
|
|
|
|
| 51 |
|
| 52 |
# Execute the C++ program
|
| 53 |
try:
|
| 54 |
+
# Path to executable is in the same directory
|
| 55 |
+
executable_path = os.path.join(current_dir, "eigen_analysis")
|
| 56 |
+
cmd = [executable_path, str(n), str(p), str(a), str(y), output_file]
|
| 57 |
+
|
| 58 |
process = subprocess.Popen(
|
| 59 |
cmd,
|
| 60 |
stdout=subprocess.PIPE,
|
|
|
|
| 102 |
except Exception as e:
|
| 103 |
st.error(f"An error occurred: {str(e)}")
|
| 104 |
|
| 105 |
+
# Show example plot on startup or previous results
|
| 106 |
+
example_file = os.path.join(output_dir, "eigenvalue_analysis.png")
|
| 107 |
+
if not os.path.exists(example_file):
|
| 108 |
st.info("π Set parameters and click 'Generate Plot' to create a visualization.")
|
| 109 |
else:
|
| 110 |
# Show the most recent plot by default
|
| 111 |
st.subheader("Current Plot")
|
| 112 |
+
img = Image.open(example_file)
|
| 113 |
st.image(img, use_column_width=True)
|
| 114 |
|
| 115 |
# Add information about the analysis
|