Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -21,33 +21,27 @@ app.add_middleware(
|
|
21 |
allow_headers=["*"],
|
22 |
)
|
23 |
|
24 |
-
|
25 |
-
async def
|
26 |
-
filename = f"{uuid4()}_{file.filename}"
|
27 |
-
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
28 |
-
async with aiofiles.open(file_path, 'wb') as out_file:
|
29 |
-
content = await file.read()
|
30 |
-
await out_file.write(content)
|
31 |
-
return file_path
|
32 |
-
|
33 |
-
# Extract text from PDF using PyPDF2
|
34 |
-
def extract_text_from_pdf(pdf_path: str) -> str:
|
35 |
-
text = ""
|
36 |
try:
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
except Exception as e:
|
43 |
-
|
|
|
|
|
44 |
|
45 |
-
@app.post("/parse-resume")
|
46 |
-
async def parse_resume(file: UploadFile = File(...)):
|
47 |
-
path = await save_file(file)
|
48 |
-
text = extract_text_from_pdf(path)
|
49 |
-
os.remove(path) # Clean up uploaded file
|
50 |
-
return JSONResponse(content={"text": text}, media_type="application/json")
|
51 |
|
52 |
@app.get("/")
|
53 |
async def root():
|
|
|
21 |
allow_headers=["*"],
|
22 |
)
|
23 |
|
24 |
+
@app.post("/parse-resume")
|
25 |
+
async def parse_resume(file: UploadFile = File(...)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
try:
|
27 |
+
print("🔄 Saving file...")
|
28 |
+
path = await save_file(file)
|
29 |
+
print(f"✅ File saved at {path}")
|
30 |
+
|
31 |
+
print("📄 Extracting text...")
|
32 |
+
text = extract_text_from_pdf(path)
|
33 |
+
print("✅ Text extracted.")
|
34 |
+
|
35 |
+
os.remove(path)
|
36 |
+
print("🧹 File removed.")
|
37 |
+
|
38 |
+
return JSONResponse(content={"text": text}, media_type="application/json")
|
39 |
+
|
40 |
except Exception as e:
|
41 |
+
import traceback
|
42 |
+
print("❌ Exception occurred:\n", traceback.format_exc())
|
43 |
+
return JSONResponse(status_code=500, content={"error": str(e)})
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
@app.get("/")
|
47 |
async def root():
|