Working flow
parent
3992cac54f
commit
8ed5f7c114
|
|
@ -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):
|
def process_pdf_async(app, file_id, file_data, filename):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
try:
|
try:
|
||||||
socketio.emit("progress", {"id": file_id, "progress": 10})
|
|
||||||
|
|
||||||
file_obj = BytesIO(file_data)
|
file_obj = BytesIO(file_data)
|
||||||
file_obj.name = filename
|
file_obj.name = filename
|
||||||
|
|
||||||
|
|
@ -82,6 +80,8 @@ def upload_file():
|
||||||
|
|
||||||
app = current_app._get_current_object()
|
app = current_app._get_current_object()
|
||||||
|
|
||||||
|
socketio.emit("progress", {"id": new_file.id, "progress": 10})
|
||||||
|
|
||||||
processing_thread = threading.Thread(
|
processing_thread = threading.Thread(
|
||||||
target=process_pdf_async,
|
target=process_pdf_async,
|
||||||
args=(app, new_file.id, file_data, fileName),
|
args=(app, new_file.id, file_data, fileName),
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,16 @@ def extract_pdf():
|
||||||
"entities": entities
|
"entities": entities
|
||||||
}
|
}
|
||||||
|
|
||||||
print(f"[EXXETA] Sending to validate service: {VALIDATE_SERVICE_URL}")
|
print(f"[SPACY] Sending to validate service: {VALIDATE_SERVICE_URL}")
|
||||||
print(f"[EXXETA] Payload: {validate_payload} entities for pitchbook {pitchbook_id}")
|
print(f"[SPACY] Payload: {validate_payload} entities for pitchbook {pitchbook_id}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.post(VALIDATE_SERVICE_URL, json=validate_payload, timeout=600)
|
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:
|
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:
|
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
|
return jsonify("Sent to validate-service"), 200
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ def send_to_coordinator_service(processed_data, request_id):
|
||||||
data=payload,
|
data=payload,
|
||||||
)
|
)
|
||||||
print(f"Result PitchBook {request_id} sent to coordinator")
|
print(f"Result PitchBook {request_id} sent to coordinator")
|
||||||
|
print(f"Result Payload {payload}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error sending ID {request_id}: {e}")
|
print(f"Error sending ID {request_id}: {e}")
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import "react-pdf/dist/esm/Page/TextLayer.css";
|
||||||
import ArrowCircleLeftIcon from "@mui/icons-material/ArrowCircleLeft";
|
import ArrowCircleLeftIcon from "@mui/icons-material/ArrowCircleLeft";
|
||||||
import ArrowCircleRightIcon from "@mui/icons-material/ArrowCircleRight";
|
import ArrowCircleRightIcon from "@mui/icons-material/ArrowCircleRight";
|
||||||
import { Box, IconButton } from "@mui/material";
|
import { Box, IconButton } from "@mui/material";
|
||||||
|
import { socket } from "../socket";
|
||||||
|
|
||||||
interface PDFViewerProps {
|
interface PDFViewerProps {
|
||||||
pitchBookId: string;
|
pitchBookId: string;
|
||||||
|
|
@ -14,6 +15,7 @@ export default function PDFViewer({ pitchBookId }: PDFViewerProps) {
|
||||||
const [numPages, setNumPages] = useState<number | null>(null);
|
const [numPages, setNumPages] = useState<number | null>(null);
|
||||||
const [pageNumber, setPageNumber] = useState(1);
|
const [pageNumber, setPageNumber] = useState(1);
|
||||||
const [containerWidth, setContainerWidth] = useState<number | null>(null);
|
const [containerWidth, setContainerWidth] = useState<number | null>(null);
|
||||||
|
const [pdfKey, setPdfKey] = useState(Date.now());
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const onDocumentLoadSuccess = ({ numPages }: { numPages: number }) => {
|
const onDocumentLoadSuccess = ({ numPages }: { numPages: number }) => {
|
||||||
|
|
@ -32,6 +34,20 @@ export default function PDFViewer({ pitchBookId }: PDFViewerProps) {
|
||||||
return () => window.removeEventListener("resize", updateWidth);
|
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 (
|
return (
|
||||||
<Box
|
<Box
|
||||||
display="flex"
|
display="flex"
|
||||||
|
|
@ -54,6 +70,7 @@ export default function PDFViewer({ pitchBookId }: PDFViewerProps) {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Document
|
<Document
|
||||||
|
key={pdfKey}
|
||||||
file={`http://localhost:5050/api/pitch_book/${pitchBookId}/download`}
|
file={`http://localhost:5050/api/pitch_book/${pitchBookId}/download`}
|
||||||
onLoadSuccess={onDocumentLoadSuccess}
|
onLoadSuccess={onDocumentLoadSuccess}
|
||||||
onLoadError={(error) =>
|
onLoadError={(error) =>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue