Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import plotly.graph_objects as go
|
|
7 |
from PIL import Image
|
8 |
import time
|
9 |
import io
|
|
|
10 |
|
11 |
# Set page config with wider layout
|
12 |
st.set_page_config(
|
@@ -115,6 +116,30 @@ if not os.path.exists(executable) or st.sidebar.button("Recompile C++ Code"):
|
|
115 |
os.chmod(executable, 0o755)
|
116 |
st.success("C++ code compiled successfully")
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
# Create tabs for different analyses
|
119 |
tab1, tab2 = st.tabs(["Eigenvalue Analysis", "Im(s) vs z Analysis"])
|
120 |
|
@@ -172,6 +197,9 @@ with tab1:
|
|
172 |
help="Convergence tolerance for golden section search",
|
173 |
key="eig_tolerance"
|
174 |
)
|
|
|
|
|
|
|
175 |
|
176 |
# Generate button
|
177 |
eig_generate_button = st.button("Generate Eigenvalue Analysis",
|
@@ -198,14 +226,14 @@ with tab1:
|
|
198 |
status_text = st.empty()
|
199 |
|
200 |
try:
|
201 |
-
#
|
202 |
data_file = os.path.join(output_dir, "eigenvalue_data.json")
|
203 |
|
204 |
# Delete previous output if exists
|
205 |
if os.path.exists(data_file):
|
206 |
os.remove(data_file)
|
207 |
|
208 |
-
#
|
209 |
cmd = [
|
210 |
executable,
|
211 |
"eigenvalues",
|
@@ -219,41 +247,28 @@ with tab1:
|
|
219 |
data_file
|
220 |
]
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
stderr=subprocess.PIPE,
|
226 |
-
text=True
|
227 |
-
)
|
228 |
-
|
229 |
-
# Show output in a status area
|
230 |
-
status_text.text("Starting calculations...")
|
231 |
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
progress_value = float(output.split(":")[1].strip())
|
240 |
-
progress_bar.progress(progress_value)
|
241 |
-
last_progress = progress_value
|
242 |
-
status_text.text(f"Calculating... {int(progress_value * 100)}% complete")
|
243 |
-
except:
|
244 |
-
pass
|
245 |
-
else:
|
246 |
-
status_text.text(output.strip())
|
247 |
-
time.sleep(0.1)
|
248 |
-
|
249 |
-
return_code = process.poll()
|
250 |
-
|
251 |
-
if return_code != 0:
|
252 |
-
error = process.stderr.read()
|
253 |
-
st.error(f"Error executing the analysis: {error}")
|
254 |
else:
|
255 |
progress_bar.progress(1.0)
|
256 |
-
status_text.text("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
# Load the results from the JSON file
|
259 |
with open(data_file, 'r') as f:
|
@@ -409,6 +424,8 @@ with tab1:
|
|
409 |
|
410 |
except Exception as e:
|
411 |
st.error(f"An error occurred: {str(e)}")
|
|
|
|
|
412 |
|
413 |
else:
|
414 |
# Try to load existing data if available
|
@@ -567,6 +584,9 @@ with tab2:
|
|
567 |
key="cubic_points"
|
568 |
)
|
569 |
|
|
|
|
|
|
|
570 |
# Show cubic equation
|
571 |
st.markdown('<div class="math-box">', unsafe_allow_html=True)
|
572 |
st.markdown("### Cubic Equation")
|
@@ -605,7 +625,7 @@ with tab2:
|
|
605 |
if os.path.exists(data_file):
|
606 |
os.remove(data_file)
|
607 |
|
608 |
-
#
|
609 |
cmd = [
|
610 |
executable,
|
611 |
"cubic",
|
@@ -616,19 +636,28 @@ with tab2:
|
|
616 |
data_file
|
617 |
]
|
618 |
|
|
|
619 |
status_text.text("Calculating Im(s) vs z values...")
|
|
|
620 |
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
st.error(f"Error executing the analysis: {process.stderr}")
|
629 |
else:
|
630 |
status_text.text("Calculations complete! Generating visualization...")
|
631 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
632 |
# Load the results from the JSON file
|
633 |
with open(data_file, 'r') as f:
|
634 |
data = json.load(f)
|
@@ -758,6 +787,8 @@ with tab2:
|
|
758 |
|
759 |
except Exception as e:
|
760 |
st.error(f"An error occurred: {str(e)}")
|
|
|
|
|
761 |
|
762 |
else:
|
763 |
# Try to load existing data if available
|
|
|
7 |
from PIL import Image
|
8 |
import time
|
9 |
import io
|
10 |
+
import sys
|
11 |
|
12 |
# Set page config with wider layout
|
13 |
st.set_page_config(
|
|
|
116 |
os.chmod(executable, 0o755)
|
117 |
st.success("C++ code compiled successfully")
|
118 |
|
119 |
+
# Helper function for running commands with better debugging
|
120 |
+
def run_command(cmd, show_output=True):
|
121 |
+
cmd_str = " ".join(cmd)
|
122 |
+
if show_output:
|
123 |
+
st.code(f"Running command: {cmd_str}", language="bash")
|
124 |
+
|
125 |
+
process = subprocess.Popen(
|
126 |
+
cmd,
|
127 |
+
stdout=subprocess.PIPE,
|
128 |
+
stderr=subprocess.PIPE,
|
129 |
+
text=True
|
130 |
+
)
|
131 |
+
|
132 |
+
stdout, stderr = process.communicate()
|
133 |
+
|
134 |
+
if process.returncode != 0:
|
135 |
+
if show_output:
|
136 |
+
st.error(f"Command failed with return code {process.returncode}")
|
137 |
+
st.error(f"Command: {cmd_str}")
|
138 |
+
st.error(f"Error output: {stderr}")
|
139 |
+
return False, stdout, stderr
|
140 |
+
|
141 |
+
return True, stdout, stderr
|
142 |
+
|
143 |
# Create tabs for different analyses
|
144 |
tab1, tab2 = st.tabs(["Eigenvalue Analysis", "Im(s) vs z Analysis"])
|
145 |
|
|
|
197 |
help="Convergence tolerance for golden section search",
|
198 |
key="eig_tolerance"
|
199 |
)
|
200 |
+
|
201 |
+
# Debug mode
|
202 |
+
debug_mode = st.checkbox("Debug Mode", value=False, key="eig_debug")
|
203 |
|
204 |
# Generate button
|
205 |
eig_generate_button = st.button("Generate Eigenvalue Analysis",
|
|
|
226 |
status_text = st.empty()
|
227 |
|
228 |
try:
|
229 |
+
# Create data file path
|
230 |
data_file = os.path.join(output_dir, "eigenvalue_data.json")
|
231 |
|
232 |
# Delete previous output if exists
|
233 |
if os.path.exists(data_file):
|
234 |
os.remove(data_file)
|
235 |
|
236 |
+
# Build command for eigenvalue analysis
|
237 |
cmd = [
|
238 |
executable,
|
239 |
"eigenvalues",
|
|
|
247 |
data_file
|
248 |
]
|
249 |
|
250 |
+
# Run the command with our helper function
|
251 |
+
status_text.text("Running eigenvalue analysis...")
|
252 |
+
success, stdout, stderr = run_command(cmd, debug_mode)
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
+
if not success:
|
255 |
+
st.error("Eigenvalue analysis failed. Please check the debug output.")
|
256 |
+
if debug_mode:
|
257 |
+
st.text("Command output:")
|
258 |
+
st.code(stdout)
|
259 |
+
st.text("Error output:")
|
260 |
+
st.code(stderr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
else:
|
262 |
progress_bar.progress(1.0)
|
263 |
+
status_text.text("Analysis complete! Generating visualization...")
|
264 |
+
|
265 |
+
# Check if the output file was created
|
266 |
+
if not os.path.exists(data_file):
|
267 |
+
st.error(f"Output file not created: {data_file}")
|
268 |
+
if debug_mode:
|
269 |
+
st.text("Command output:")
|
270 |
+
st.code(stdout)
|
271 |
+
st.stop()
|
272 |
|
273 |
# Load the results from the JSON file
|
274 |
with open(data_file, 'r') as f:
|
|
|
424 |
|
425 |
except Exception as e:
|
426 |
st.error(f"An error occurred: {str(e)}")
|
427 |
+
if debug_mode:
|
428 |
+
st.exception(e)
|
429 |
|
430 |
else:
|
431 |
# Try to load existing data if available
|
|
|
584 |
key="cubic_points"
|
585 |
)
|
586 |
|
587 |
+
# Debug mode
|
588 |
+
cubic_debug_mode = st.checkbox("Debug Mode", value=False, key="cubic_debug")
|
589 |
+
|
590 |
# Show cubic equation
|
591 |
st.markdown('<div class="math-box">', unsafe_allow_html=True)
|
592 |
st.markdown("### Cubic Equation")
|
|
|
625 |
if os.path.exists(data_file):
|
626 |
os.remove(data_file)
|
627 |
|
628 |
+
# Build command for cubic equation analysis
|
629 |
cmd = [
|
630 |
executable,
|
631 |
"cubic",
|
|
|
636 |
data_file
|
637 |
]
|
638 |
|
639 |
+
# Run the command with our helper function
|
640 |
status_text.text("Calculating Im(s) vs z values...")
|
641 |
+
success, stdout, stderr = run_command(cmd, cubic_debug_mode)
|
642 |
|
643 |
+
if not success:
|
644 |
+
st.error("Cubic equation analysis failed. Please check the debug output.")
|
645 |
+
if cubic_debug_mode:
|
646 |
+
st.text("Command output:")
|
647 |
+
st.code(stdout)
|
648 |
+
st.text("Error output:")
|
649 |
+
st.code(stderr)
|
|
|
650 |
else:
|
651 |
status_text.text("Calculations complete! Generating visualization...")
|
652 |
|
653 |
+
# Check if the output file was created
|
654 |
+
if not os.path.exists(data_file):
|
655 |
+
st.error(f"Output file not created: {data_file}")
|
656 |
+
if cubic_debug_mode:
|
657 |
+
st.text("Command output:")
|
658 |
+
st.code(stdout)
|
659 |
+
st.stop()
|
660 |
+
|
661 |
# Load the results from the JSON file
|
662 |
with open(data_file, 'r') as f:
|
663 |
data = json.load(f)
|
|
|
787 |
|
788 |
except Exception as e:
|
789 |
st.error(f"An error occurred: {str(e)}")
|
790 |
+
if cubic_debug_mode:
|
791 |
+
st.exception(e)
|
792 |
|
793 |
else:
|
794 |
# Try to load existing data if available
|