diff --git a/project/backend/coordinator/controller/pitch_book_controller.py b/project/backend/coordinator/controller/pitch_book_controller.py index c4d7f3a..e04e31e 100644 --- a/project/backend/coordinator/controller/pitch_book_controller.py +++ b/project/backend/coordinator/controller/pitch_book_controller.py @@ -16,8 +16,6 @@ OCR_SERVICE_URL = os.getenv("OCR_SERVICE_URL", "http://localhost:5051") def process_pdf_async(app, file_id, file_data, filename): with app.app_context(): try: - socketio.emit("progress", {"id": file_id, "progress": 10}) - file_obj = BytesIO(file_data) file_obj.name = filename @@ -82,6 +80,8 @@ def upload_file(): app = current_app._get_current_object() + socketio.emit("progress", {"id": new_file.id, "progress": 10}) + processing_thread = threading.Thread( target=process_pdf_async, args=(app, new_file.id, file_data, fileName), diff --git a/project/backend/spacy-service/app.py b/project/backend/spacy-service/app.py index 503910d..4e32067 100644 --- a/project/backend/spacy-service/app.py +++ b/project/backend/spacy-service/app.py @@ -24,16 +24,16 @@ def extract_pdf(): "entities": entities } - print(f"[EXXETA] Sending to validate service: {VALIDATE_SERVICE_URL}") - print(f"[EXXETA] Payload: {validate_payload} entities for pitchbook {pitchbook_id}") + print(f"[SPACY] Sending to validate service: {VALIDATE_SERVICE_URL}") + print(f"[SPACY] Payload: {validate_payload} entities for pitchbook {pitchbook_id}") try: response = requests.post(VALIDATE_SERVICE_URL, json=validate_payload, timeout=600) - print(f"[EXXETA] Validate service response: {response.status_code}") + print(f"[SPACY] Validate service response: {response.status_code}") if response.status_code != 200: - print(f"[EXXETA] Validate service error: {response.text}") + print(f"[SPACY] Validate service error: {response.text}") except Exception as e: - print(f"[EXXETA] Error sending to validate service: {e}") + print(f"[SPACY] Error sending to validate service: {e}") return jsonify("Sent to validate-service"), 200 diff --git a/project/backend/validate-service/app.py b/project/backend/validate-service/app.py index 22fc212..2c821d5 100644 --- a/project/backend/validate-service/app.py +++ b/project/backend/validate-service/app.py @@ -32,6 +32,7 @@ def send_to_coordinator_service(processed_data, request_id): data=payload, ) print(f"Result PitchBook {request_id} sent to coordinator") + print(f"Result Payload {payload}") except Exception as e: print(f"Error sending ID {request_id}: {e}") diff --git a/project/frontend/src/components/pdfViewer.tsx b/project/frontend/src/components/pdfViewer.tsx index 85034ab..85649ed 100644 --- a/project/frontend/src/components/pdfViewer.tsx +++ b/project/frontend/src/components/pdfViewer.tsx @@ -5,6 +5,7 @@ import "react-pdf/dist/esm/Page/TextLayer.css"; import ArrowCircleLeftIcon from "@mui/icons-material/ArrowCircleLeft"; import ArrowCircleRightIcon from "@mui/icons-material/ArrowCircleRight"; import { Box, IconButton } from "@mui/material"; +import { socket } from "../socket"; interface PDFViewerProps { pitchBookId: string; @@ -14,6 +15,7 @@ export default function PDFViewer({ pitchBookId }: PDFViewerProps) { const [numPages, setNumPages] = useState(null); const [pageNumber, setPageNumber] = useState(1); const [containerWidth, setContainerWidth] = useState(null); + const [pdfKey, setPdfKey] = useState(Date.now()); const containerRef = useRef(null); const onDocumentLoadSuccess = ({ numPages }: { numPages: number }) => { @@ -32,6 +34,20 @@ export default function PDFViewer({ pitchBookId }: PDFViewerProps) { return () => window.removeEventListener("resize", updateWidth); }, []); + useEffect(() => { + const handleProgress = (data: { id: number; progress: number }) => { + if (data.id.toString() === pitchBookId && data.progress === 50) { + setPdfKey(Date.now()); + } + }; + + socket.on("progress", handleProgress); + + return () => { + socket.off("progress", handleProgress); + }; + }, [pitchBookId]); + return (