Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import subprocess
|
|
3 |
import os
|
4 |
from PIL import Image
|
5 |
import time
|
6 |
-
import
|
7 |
|
8 |
# Set page config
|
9 |
st.set_page_config(
|
@@ -25,6 +25,50 @@ 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")
|
30 |
|
@@ -51,9 +95,7 @@ if st.sidebar.button("Generate Plot", type="primary"):
|
|
51 |
|
52 |
# Execute the C++ program
|
53 |
try:
|
54 |
-
|
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,
|
|
|
3 |
import os
|
4 |
from PIL import Image
|
5 |
import time
|
6 |
+
import numpy as np
|
7 |
|
8 |
# Set page config
|
9 |
st.set_page_config(
|
|
|
25 |
output_dir = os.path.join(current_dir, "output")
|
26 |
os.makedirs(output_dir, exist_ok=True)
|
27 |
|
28 |
+
# Compile the C++ code at runtime
|
29 |
+
cpp_file = os.path.join(current_dir, "app.cpp")
|
30 |
+
executable = os.path.join(current_dir, "eigen_analysis")
|
31 |
+
|
32 |
+
# Check if cpp file exists
|
33 |
+
if not os.path.exists(cpp_file):
|
34 |
+
st.error(f"C++ source file not found at: {cpp_file}")
|
35 |
+
st.stop()
|
36 |
+
|
37 |
+
# Compile the C++ code
|
38 |
+
try:
|
39 |
+
compile_cmd = f"g++ -o {executable} {cpp_file} $(pkg-config --cflags --libs opencv4) -std=c++11"
|
40 |
+
compile_result = subprocess.run(
|
41 |
+
compile_cmd,
|
42 |
+
shell=True,
|
43 |
+
capture_output=True,
|
44 |
+
text=True
|
45 |
+
)
|
46 |
+
|
47 |
+
if compile_result.returncode != 0:
|
48 |
+
st.error(f"Failed to compile C++ code: {compile_result.stderr}")
|
49 |
+
st.info("Attempting alternate compilation command...")
|
50 |
+
|
51 |
+
# Try alternate compilation without pkg-config
|
52 |
+
compile_cmd = f"g++ -o {executable} {cpp_file} -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -std=c++11"
|
53 |
+
compile_result = subprocess.run(
|
54 |
+
compile_cmd,
|
55 |
+
shell=True,
|
56 |
+
capture_output=True,
|
57 |
+
text=True
|
58 |
+
)
|
59 |
+
|
60 |
+
if compile_result.returncode != 0:
|
61 |
+
st.error(f"Failed to compile with alternate command: {compile_result.stderr}")
|
62 |
+
st.stop()
|
63 |
+
|
64 |
+
# Make sure the executable is executable
|
65 |
+
os.chmod(executable, 0o755)
|
66 |
+
st.success("C++ code compiled successfully")
|
67 |
+
|
68 |
+
except Exception as e:
|
69 |
+
st.error(f"Error during compilation: {str(e)}")
|
70 |
+
st.stop()
|
71 |
+
|
72 |
# Input parameters sidebar
|
73 |
st.sidebar.header("Parameters")
|
74 |
|
|
|
95 |
|
96 |
# Execute the C++ program
|
97 |
try:
|
98 |
+
cmd = [executable, str(n), str(p), str(a), str(y), output_file]
|
|
|
|
|
99 |
|
100 |
process = subprocess.Popen(
|
101 |
cmd,
|