Spaces:
Sleeping
Sleeping
Create resume.py
Browse files
resume.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import PyPDF2
|
2 |
+
from PyPDF2 import PdfReader
|
3 |
+
import docx
|
4 |
+
import os
|
5 |
+
import logging
|
6 |
+
from textwrap import dedent
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
def extract_text_from_file(file):
|
10 |
+
if file is None:
|
11 |
+
return "No file uploaded!"
|
12 |
+
|
13 |
+
# Determine file type
|
14 |
+
file_type = file.name.split('.')[-1].lower()
|
15 |
+
|
16 |
+
text = ""
|
17 |
+
try:
|
18 |
+
if file_type == "pdf":
|
19 |
+
# Extract text from PDF
|
20 |
+
reader = PdfReader(file)
|
21 |
+
for page in reader.pages:
|
22 |
+
text += page.extract_text()
|
23 |
+
elif file_type == "docx":
|
24 |
+
# Extract text from DOCX
|
25 |
+
doc = docx.Document(file)
|
26 |
+
for paragraph in doc.paragraphs:
|
27 |
+
text += paragraph.text + "\n"
|
28 |
+
elif file_type == "txt":
|
29 |
+
# Extract text from TXT
|
30 |
+
text = file.read().decode("utf-8")
|
31 |
+
else:
|
32 |
+
return "Unsupported file type! Please upload a PDF, DOCX, or TXT file."
|
33 |
+
except Exception as e:
|
34 |
+
return f"Error reading file: {str(e)}"
|
35 |
+
|
36 |
+
return text.strip()
|