Update src/streamlit_app.py
Browse files- src/streamlit_app.py +26 -3
src/streamlit_app.py
CHANGED
|
@@ -46,11 +46,15 @@ with loading_placeholder:
|
|
| 46 |
</div>
|
| 47 |
""", unsafe_allow_html=True)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
# Import dependencies with comprehensive error handling
|
| 50 |
try:
|
| 51 |
import numpy as np
|
| 52 |
import pandas as pd
|
| 53 |
-
import cv2
|
| 54 |
import time
|
| 55 |
import tempfile
|
| 56 |
import json
|
|
@@ -61,8 +65,27 @@ try:
|
|
| 61 |
from typing import NamedTuple
|
| 62 |
import subprocess
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Deep learning imports
|
| 68 |
import keras
|
|
|
|
| 46 |
</div>
|
| 47 |
""", unsafe_allow_html=True)
|
| 48 |
|
| 49 |
+
# Set environment variables before any imports
|
| 50 |
+
os.environ["KERAS_BACKEND"] = "torch"
|
| 51 |
+
os.environ["OPENCV_LOG_LEVEL"] = "ERROR"
|
| 52 |
+
os.environ["QT_QPA_PLATFORM"] = "offscreen" # For headless OpenCV
|
| 53 |
+
|
| 54 |
# Import dependencies with comprehensive error handling
|
| 55 |
try:
|
| 56 |
import numpy as np
|
| 57 |
import pandas as pd
|
|
|
|
| 58 |
import time
|
| 59 |
import tempfile
|
| 60 |
import json
|
|
|
|
| 65 |
from typing import NamedTuple
|
| 66 |
import subprocess
|
| 67 |
|
| 68 |
+
# Import OpenCV with headless configuration and fallback
|
| 69 |
+
cv2 = None
|
| 70 |
+
try:
|
| 71 |
+
import cv2
|
| 72 |
+
# Ensure OpenCV uses headless backend
|
| 73 |
+
if hasattr(cv2, 'setNumThreads'):
|
| 74 |
+
cv2.setNumThreads(1)
|
| 75 |
+
# Test basic functionality
|
| 76 |
+
_ = cv2.__version__
|
| 77 |
+
except ImportError as opencv_error:
|
| 78 |
+
loading_placeholder.empty()
|
| 79 |
+
st.error(f"β OpenCV import failed: {opencv_error}")
|
| 80 |
+
st.error("Please run the setup script: `setup_windows.bat` or `./setup_windows.ps1`")
|
| 81 |
+
st.info("π‘ Alternative: pip uninstall opencv-python && pip install opencv-python-headless")
|
| 82 |
+
st.stop()
|
| 83 |
+
except Exception as opencv_error:
|
| 84 |
+
loading_placeholder.empty()
|
| 85 |
+
st.error(f"β OpenCV configuration error: {opencv_error}")
|
| 86 |
+
st.error("This might be a headless display issue. Please use opencv-python-headless.")
|
| 87 |
+
st.info("π‘ Try: pip install opencv-python-headless==4.8.1.78")
|
| 88 |
+
st.stop()
|
| 89 |
|
| 90 |
# Deep learning imports
|
| 91 |
import keras
|