Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -21,6 +21,31 @@ app.add_middleware(
|
|
21 |
allow_headers=["*"],
|
22 |
)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
@app.post("/parse-resume")
|
25 |
async def parse_resume(file: UploadFile = File(...)):
|
26 |
try:
|
|
|
21 |
allow_headers=["*"],
|
22 |
)
|
23 |
|
24 |
+
|
25 |
+
# ✅ Save uploaded file asynchronously
|
26 |
+
async def save_file(file: UploadFile) -> str:
|
27 |
+
filename = f"{uuid4()}_{file.filename}"
|
28 |
+
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
29 |
+
async with aiofiles.open(file_path, 'wb') as out_file:
|
30 |
+
content = await file.read()
|
31 |
+
await out_file.write(content)
|
32 |
+
return file_path
|
33 |
+
|
34 |
+
# ✅ Extra
|
35 |
+
ct text from PDF using PyPDF2
|
36 |
+
def extract_text_from_pdf(pdf_path: str) -> str:
|
37 |
+
text = ""
|
38 |
+
try:
|
39 |
+
with open(pdf_path, "rb") as file:
|
40 |
+
pdf_reader = PyPDF2.PdfReader(file)
|
41 |
+
for page in pdf_reader.pages:
|
42 |
+
page_text = page.extract_text()
|
43 |
+
if page_text:
|
44 |
+
text += page_text + "\n"
|
45 |
+
return text.strip()
|
46 |
+
except Exception as e:
|
47 |
+
return f"Error extracting text: {str(e)}"
|
48 |
+
|
49 |
@app.post("/parse-resume")
|
50 |
async def parse_resume(file: UploadFile = File(...)):
|
51 |
try:
|