Spaces:
Running
Running
Commit ·
8d465e5
1
Parent(s): 0e82360
fix: non-blocking async timeout for vision analysis with fast Tesseract OCR fallback
Browse files
RAG_FULL_APPLICATION_BACKEND/app/services/file_parser.py
CHANGED
|
@@ -62,14 +62,18 @@ async def _parse_image(file_path: str, job_id: str, ws_manager: Any, user_id: st
|
|
| 62 |
except Exception as e:
|
| 63 |
logger.warning(f"Tesseract OCR failed: {e}")
|
| 64 |
|
| 65 |
-
# 2. Vision Space Analysis (
|
| 66 |
try:
|
| 67 |
await ws_manager.emit(job_id, user_id, {"step": "IMAGE_ANALYZE", "color": "#8B5CF6", "detail": "Analyzing visual image contents..."})
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
if description and "failed to understand" not in description.lower():
|
| 70 |
extracted_content.append(f"Visual Scene Description:\n{description}")
|
| 71 |
except Exception as e:
|
| 72 |
-
logger.warning(f"Vision space analysis skipped/
|
| 73 |
|
| 74 |
# 3. Fallback to image metadata if no text or vision
|
| 75 |
if not extracted_content:
|
|
|
|
| 62 |
except Exception as e:
|
| 63 |
logger.warning(f"Tesseract OCR failed: {e}")
|
| 64 |
|
| 65 |
+
# 2. Vision Space Analysis (with non-blocking 4s timeout)
|
| 66 |
try:
|
| 67 |
await ws_manager.emit(job_id, user_id, {"step": "IMAGE_ANALYZE", "color": "#8B5CF6", "detail": "Analyzing visual image contents..."})
|
| 68 |
+
import asyncio
|
| 69 |
+
description = await asyncio.wait_for(
|
| 70 |
+
asyncio.to_thread(vision_service.understand_image, file_path),
|
| 71 |
+
timeout=4.0
|
| 72 |
+
)
|
| 73 |
if description and "failed to understand" not in description.lower():
|
| 74 |
extracted_content.append(f"Visual Scene Description:\n{description}")
|
| 75 |
except Exception as e:
|
| 76 |
+
logger.warning(f"Vision space analysis skipped/timed out: {e}")
|
| 77 |
|
| 78 |
# 3. Fallback to image metadata if no text or vision
|
| 79 |
if not extracted_content:
|