Spaces:
Sleeping
Sleeping
| import os | |
| from uuid import uuid4 | |
| import uvicorn | |
| from fastapi import FastAPI, UploadFile, File | |
| from fastapi.responses import JSONResponse | |
| from fastapi.middleware.cors import CORSMiddleware | |
| import aiofiles | |
| import PyPDF2 | |
| UPLOAD_FOLDER = "uploads" | |
| os.makedirs(UPLOAD_FOLDER, exist_ok=True) | |
| app = FastAPI() | |
| # Enable CORS (you can restrict origins later) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| async def parse_resume(file: UploadFile = File(...)): | |
| try: | |
| print("π Saving file...") | |
| path = await save_file(file) | |
| print(f"β File saved at {path}") | |
| print("π Extracting text...") | |
| text = extract_text_from_pdf(path) | |
| print("β Text extracted.") | |
| os.remove(path) | |
| print("π§Ή File removed.") | |
| return JSONResponse(content={"text": text}, media_type="application/json") | |
| except Exception as e: | |
| import traceback | |
| print("β Exception occurred:\n", traceback.format_exc()) | |
| return JSONResponse(status_code=500, content={"error": str(e)}) | |
| async def root(): | |
| return {"message": "Resume PDF Text Extractor is running π―"} | |
| if __name__ == "__main__": | |
| uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True) |