euler314 commited on
Commit
13b3948
·
verified ·
1 Parent(s): 3dfdf4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -3,7 +3,9 @@ import subprocess
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(
@@ -34,9 +36,9 @@ 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,
@@ -46,10 +48,10 @@ try:
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,
@@ -58,8 +60,18 @@ try:
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)
 
3
  import os
4
  from PIL import Image
5
  import time
6
+ import io
7
  import numpy as np
8
+ import tempfile
9
 
10
  # Set page config
11
  st.set_page_config(
 
36
  st.error(f"C++ source file not found at: {cpp_file}")
37
  st.stop()
38
 
39
+ # Compile the C++ code (we now have the required packages from packages.txt)
40
  try:
41
+ compile_cmd = f"g++ -o {executable} {cpp_file} `pkg-config --cflags --libs opencv4` -std=c++11"
42
  compile_result = subprocess.run(
43
  compile_cmd,
44
  shell=True,
 
48
 
49
  if compile_result.returncode != 0:
50
  st.error(f"Failed to compile C++ code: {compile_result.stderr}")
51
+ # Try alternate compiler flag
52
  st.info("Attempting alternate compilation command...")
53
 
54
+ compile_cmd = f"g++ -o {executable} {cpp_file} `pkg-config --cflags --libs opencv` -std=c++11"
 
55
  compile_result = subprocess.run(
56
  compile_cmd,
57
  shell=True,
 
60
  )
61
 
62
  if compile_result.returncode != 0:
63
+ # Try with direct linking
64
+ compile_cmd = f"g++ -o {executable} {cpp_file} -I/usr/include/opencv4 -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -std=c++11"
65
+ compile_result = subprocess.run(
66
+ compile_cmd,
67
+ shell=True,
68
+ capture_output=True,
69
+ text=True
70
+ )
71
+
72
+ if compile_result.returncode != 0:
73
+ st.error(f"All compilation attempts failed. Last error: {compile_result.stderr}")
74
+ st.stop()
75
 
76
  # Make sure the executable is executable
77
  os.chmod(executable, 0o755)