File size: 2,307 Bytes
6c294e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8f7500
 
 
 
6c294e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import PyPDF2
import docx
import os
from sentence_transformers import SentenceTransformer
from fpdf import FPDF
from io import StringIO

# Function to extract text from different file types
def extract_text(uploaded_file, file_type):
    if file_type == "pdf":
        return extract_text_pdf(uploaded_file)
    elif file_type == "docx":
        return extract_text_docx(uploaded_file)
    elif file_type == "txt":
        return extract_text_txt(uploaded_file)
    elif file_type == "html":
        return extract_text_html(uploaded_file)

# Extract text from PDF file
def extract_text_pdf(uploaded_file):
    reader = PyPDF2.PdfReader(uploaded_file)
    text = ""
    for page in reader.pages:
        text += page.extract_text() or ""
    return text

# Extract text from DOCX file
def extract_text_docx(uploaded_file):
    doc = docx.Document(uploaded_file)
    text = ''
    for para in doc.paragraphs:
        text += para.text + '\n'
    return text

# Extract text from TXT file
def extract_text_txt(uploaded_file):
    text = uploaded_file.read().decode("utf-8")
    return text

# Extract text from HTML file
def extract_text_html(uploaded_file):
    from bs4 import BeautifulSoup
    soup = BeautifulSoup(uploaded_file, 'html.parser')
    text = soup.get_text()
    return text

# Function to render different resume templates
def render_template(tailored_resume, template="template1"):
    if template == "template1":
        return render_template1(tailored_resume)
    elif template == "template2":
        return render_template2(tailored_resume)
    elif template == "template3":
        return render_template3(tailored_resume)
    return tailored_resume

# Template 1 rendering
def render_template1(tailored_resume):
    # Here, you can define a simple formatting style for template 1
    return f"--- Template 1 ---\n\n{tailored_resume}\n--- End of Template 1 ---"

# Template 2 rendering
def render_template2(tailored_resume):
    # Here, you can define a simple formatting style for template 2
    return f"=== Template 2 ===\n\n{tailored_resume}\n=== End of Template 2 ==="

# Template 3 rendering
def render_template3(tailored_resume):
    # Here, you can define a simple formatting style for template 3
    return f"### Template 3 ###\n\n{tailored_resume}\n### End of Template 3 ###"