Spaces:
Running
Running
| import searchworks | |
| import sys | |
| print(f"--- [DEBUG] OCR SERVICE PATH: {__file__} ---") | |
| print(f"--- [DEBUG] SEARCHWORKS PATH: {searchworks.__file__} ---") | |
| try: | |
| with open("ocr_service_running.txt", "w") as f: | |
| f.write(f"RUNNING: {__file__}\n") | |
| f.write(f"SEARCHWORKS: {searchworks.__file__}\n") | |
| except Exception as e: | |
| print(f"--- [WARNING] Could not write ocr_service_running.txt: {e} ---") | |
| import logging | |
| import numpy as np | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| # Initialize the main app | |
| app = FastAPI(title="Yimlo OCR Verification Microservices") | |
| # Enable CORS so the React frontend can communicate with this API | |
| # Allow all origins for production since Netlify creates dynamic preview URLs | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=False, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| async def root(): | |
| return {"status": "online", "message": "Yimlo OCR Verification API is running. Direct access is limited to internal services."} | |
| # Import the modular verification routers | |
| from routers import verify_id, verify_address, verify_bank, verify_credit, professional, verify_health, verify_agent_profile | |
| # Include routes from each dedicated service module. | |
| app.include_router(verify_id.router, tags=["Proof of ID"]) | |
| app.include_router(verify_address.router, tags=["Proof of Address"]) | |
| app.include_router(verify_bank.router, tags=["Bank Account"]) | |
| app.include_router(verify_credit.router, tags=["Credit Score"]) | |
| app.include_router(professional.router, tags=["Professional Profile"]) | |
| app.include_router(verify_health.router, tags=["Medical Health"]) | |
| app.include_router(verify_agent_profile.router, tags=["Agent Profile"]) | |
| # Include the SW360 Live Verification mock endpoints | |
| # Include the SW360 Live Verification mock endpoints | |
| from searchworks import verify_person, verify_address as sw_verify_address, verify_bank, verify_credit, verify_qualification, verify_employer, verify_company | |
| from fastapi import Form, HTTPException | |
| async def live_verify_person( | |
| idNumber: str = Form(...), | |
| firstName: str = Form(...), | |
| surname: str = Form(...) | |
| ): | |
| try: | |
| result = verify_person(idNumber, firstName, surname) | |
| print(f"--- [SW360] Result: verified={result.get('verified')}, message={result.get('message')} ---") | |
| return result | |
| except Exception as e: | |
| import traceback | |
| traceback.print_exc() | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def live_verify_address_sw( | |
| idNumber: str = Form(...), | |
| address: str = Form(...) | |
| ): | |
| try: | |
| return sw_verify_address(idNumber, address) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def live_verify_bank_sw( | |
| idNumber: str = Form(...), | |
| surname: str = Form(...), | |
| initials: str = Form(...), | |
| accountType: str = Form(...), | |
| accountNumber: str = Form(...), | |
| branchCode: str = Form(...) | |
| ): | |
| try: | |
| return verify_bank(accountType, accountNumber, branchCode, initials, surname, idNumber) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def live_verify_credit_sw( | |
| idNumber: str = Form(...), | |
| surname: str = Form(...), | |
| firstName: str = Form(...) | |
| ): | |
| try: | |
| return verify_credit(idNumber, surname, firstName) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def live_verify_qualification_sw( | |
| idNumber: str = Form(...) | |
| ): | |
| try: | |
| return verify_qualification(idNumber) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def live_verify_employer_sw( | |
| idNumber: str = Form(...), | |
| surname: str = Form(...), | |
| firstName: str = Form(...), | |
| employerName: str = Form(...) | |
| ): | |
| try: | |
| return verify_employer(idNumber, firstName, surname, employerName) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def live_verify_company_sw( | |
| companyName: str = Form(...), | |
| agentName: str = Form("UnknownAgent"), | |
| registrationNumber: str = Form("") | |
| ): | |
| try: | |
| return verify_company(companyName, agentName, registrationNumber) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| if __name__ == "__main__": | |
| import uvicorn | |
| # Make sure we initialize the GPU reader model before accepting traffic | |
| from dependencies import reader | |
| print("--- [STARTUP] Warming up EasyOCR model... ---") | |
| dummy_img = np.zeros((100, 100, 3), dtype=np.uint8) | |
| reader.readtext(dummy_img) | |
| print("--- [STARTUP] Warmup complete. Modular Verification Services Online. ---") | |
| uvicorn.run("ocr_service:app", host="0.0.0.0", port=7860, reload=False) | |