Spaces:
Sleeping
Sleeping
Upload streamlit_app.py
Browse files- src/streamlit_app.py +7 -5
src/streamlit_app.py
CHANGED
|
@@ -153,13 +153,14 @@ div[data-testid="stFileUploader"] * {
|
|
| 153 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 154 |
# MODELS & OCR LOGIC
|
| 155 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 156 |
-
|
|
|
|
| 157 |
def load_vision_engine():
|
| 158 |
import logging
|
| 159 |
logging.getLogger("easyocr").setLevel(logging.ERROR)
|
| 160 |
return easyocr.Reader(['en'], gpu=torch.cuda.is_available())
|
| 161 |
|
| 162 |
-
|
| 163 |
def load_trocr_model(model_path):
|
| 164 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 165 |
|
|
@@ -262,9 +263,10 @@ def main():
|
|
| 262 |
if run_scan_trigger:
|
| 263 |
start = time.time()
|
| 264 |
|
| 265 |
-
#
|
| 266 |
-
|
| 267 |
-
|
|
|
|
| 268 |
|
| 269 |
decoded, scores = [], []
|
| 270 |
total_crops = len(crops)
|
|
|
|
| 153 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 154 |
# MODELS & OCR LOGIC
|
| 155 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 156 |
+
# THE KILL-SWITCH: show_spinner=False completely deletes the un-styleable white cache boxes
|
| 157 |
+
@st.cache_resource(show_spinner=False)
|
| 158 |
def load_vision_engine():
|
| 159 |
import logging
|
| 160 |
logging.getLogger("easyocr").setLevel(logging.ERROR)
|
| 161 |
return easyocr.Reader(['en'], gpu=torch.cuda.is_available())
|
| 162 |
|
| 163 |
+
@st.cache_resource(show_spinner=False)
|
| 164 |
def load_trocr_model(model_path):
|
| 165 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 166 |
|
|
|
|
| 263 |
if run_scan_trigger:
|
| 264 |
start = time.time()
|
| 265 |
|
| 266 |
+
# The fully-styled, dark-mode spinner handles the wait time so the app doesn't freeze or refresh weirdly
|
| 267 |
+
with st.spinner("Allocating Neural Resources & Loading Weights..."):
|
| 268 |
+
proc, model, device = load_trocr_model(m_map[model_choice])
|
| 269 |
+
crops = extract_lines(st.session_state.image_data, reader)
|
| 270 |
|
| 271 |
decoded, scores = [], []
|
| 272 |
total_crops = len(crops)
|