File size: 9,315 Bytes
b110ab4
 
 
 
 
112a5cf
a82a79d
b110ab4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1b6dad
b110ab4
 
 
 
112a5cf
 
 
 
 
 
 
 
 
fee5ac0
112a5cf
 
 
a82a79d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b110ab4
cfaa1f9
a82a79d
 
 
6bc6c8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a82a79d
 
 
 
 
 
 
 
 
 
 
 
b110ab4
6bc6c8a
b110ab4
 
6bc6c8a
 
 
 
 
 
 
 
 
b110ab4
 
6bc6c8a
41fa798
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6bc6c8a
41fa798
fa10662
41fa798
fa10662
 
41fa798
 
 
 
 
 
 
 
 
 
6bc6c8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import streamlit as st
import os
from dotenv import load_dotenv
from langchain_community.llms import OpenAI
from langchain_google_genai import ChatGoogleGenerativeAI
from fpdf import FPDF
import fitz 

# Load environment variables
load_dotenv()


def generate_resume(details):
    prompt = f"""
    Create an ATS-optimized resume based on the following details:

    Name: {details['name']}
    Contact Information: {details['contact']}
    LinkedIn Profile: {details['linkedin']}
    Professional Summary: {details['summary']}
    Work Experience: {details['experience']}
    Education: {details['education']}
    Skills: {details['skills']}
    Certifications: {details['certifications']}
    Projects: {details['projects']}

    Provide the resume in a well-structured format.
    """
    
    llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"],max_tokens=1500)
    resume = llm(prompt)
    
    return resume



def create_pdf(resume_text, filename):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_auto_page_break(auto=True, margin=15)
    pdf.set_font("Arial", size=12)
    
    for line in resume_text.split('\n'):
        pdf.multi_cell(0, 10, line.encode('latin-1', 'replace').decode('latin-1'))
    
    pdf.output(filename)


def extract_text_from_pdf(pdf_file):
    doc = fitz.open(stream=pdf_file.read(), filetype="pdf")
    text = ""
    for page in doc:
        text += page.get_text()
    return text

def parse_extracted_text(text):
    details = {
        'name': "",
        'contact': "",
        'linkedin': "",
        'summary': "",
        'experience': "",
        'education': "",
        'skills': "",
        'certifications': "",
        'projects': ""
    }
    
    # Here, you would implement parsing logic to extract details from the text.
    # For simplicity, this example assumes the text is well-structured and uses basic keyword extraction.
    # In a real-world scenario, you would use more sophisticated text parsing techniques.
    
    lines = text.split('\n')
    for i, line in enumerate(lines):
        if "Name:" in line:
            details['name'] = line.split("Name:")[1].strip()
        elif "Contact Information:" in line:
            details['contact'] = line.split("Contact Information:")[1].strip()
        elif "LinkedIn Profile:" in line:
            details['linkedin'] = line.split("LinkedIn Profile:")[1].strip()
        elif "Professional Summary:" in line:
            details['summary'] = line.split("Professional Summary:")[1].strip()
        elif "Work Experience:" in line:
            details['experience'] = " ".join(lines[i+1:i+5]).strip()
        elif "Education:" in line:
            details['education'] = " ".join(lines[i+1:i+3]).strip()
        elif "Skills:" in line:
            details['skills'] = line.split("Skills:")[1].strip()
        elif "Certifications:" in line:
            details['certifications'] = line.split("Certifications:")[1].strip()
        elif "Projects:" in line:
            details['projects'] = " ".join(lines[i+1:i+3]).strip()

    return details




def app():
    st.title("Resume Creation")
    uploaded_file = st.file_uploader("Upload a resume to pre-fill details", type=["pdf"])
    
    if uploaded_file:
        if st.button("Submit"):
            extracted_text = extract_text_from_pdf(uploaded_file)
            details = parse_extracted_text(extracted_text)
            st.write("Extracted Text:", extracted_text)  # Debug: Show the extracted text
            st.write("Parsed Details:", details)  # Debug: Show the parsed details
        else:
            details = {
                'name': "",
                'contact': "",
                'linkedin': "",
                'summary': "",
                'experience': "",
                'education': "",
                'skills': "",
                'certifications': "",
                'projects': ""
            }
    else:
        details = {
            'name': "",
            'contact': "",
            'linkedin': "",
            'summary': "",
            'experience': "",
            'education': "",
            'skills': "",
            'certifications': "",
            'projects': ""
        }

    with st.form("resume_form"):
        st.header("Enter your details to generate an ATS-optimized resume")
        
        name = st.text_input("Name", value=details['name'])
        contact = st.text_area("Contact Information (phone, email, address)", value=details['contact'])
        linkedin = st.text_input("LinkedIn Profile URL", value=details['linkedin'])
        summary = st.text_area("Professional Summary", value=details['summary'])
        experience = st.text_area("Work Experience (provide details of each job including company name, job title, duration, and responsibilities)", value=details['experience'])
        education = st.text_area("Education (provide details of degrees, institutions, and graduation dates)", value=details['education'])
        skills = st.text_area("Skills (list your skills)", value=details['skills'])
        certifications = st.text_area("Certifications (list any relevant certifications)", value=details['certifications'])
        projects = st.text_area("Projects (provide details of your projects)", value=details['projects'])
        
        submitted = st.form_submit_button("Generate Resume")
    
    if submitted:
        if name and contact and linkedin and summary and experience and education and skills and certifications and projects:
            details = {
                'name': name,
                'contact': contact,
                'linkedin': linkedin,
                'summary': summary,
                'experience': experience,
                'education': education,
                'skills': skills,
                'certifications': certifications,
                'projects': projects
            }
            resume = generate_resume(details)
            st.header("Generated Resume")
            st.text(resume)
            
            # Save resume as PDF and provide download link

            pdf_filename = "resume.pdf"
            create_pdf(resume, pdf_filename)
            
            
            with open(pdf_filename, "rb") as pdf_file:
                st.download_button(
                    label="Download Resume as PDF",
                    data=pdf_file,
                    file_name=pdf_filename,
                    mime="application/pdf"
                )
        else:
            st.error("Please fill in all the fields to generate the resume.")
    # st.title("Resume Creation")

    # uploaded_file = st.file_uploader("Upload a resume to pre-fill details", type=["pdf"])
    
    # if uploaded_file:
    #     extracted_text = extract_text_from_pdf(uploaded_file)
    #     details = parse_extracted_text(extracted_text)
    # else:
    #     details = {
    #         'name': "",
    #         'contact': "",
    #         'linkedin': "",
    #         'summary': "",
    #         'experience': "",
    #         'education': "",
    #         'skills': "",
    #         'certifications': "",
    #         'projects': ""
    #     }

    # with st.form("profile_form"):
    #     st.header("Enter your details to generate an ATS-optimized resume")
        
    #     name = st.text_input("Name")
    #     contact = st.text_area("Contact Information (phone, email, address)")
    #     linkedin = st.text_input("LinkedIn Profile URL")
    #     summary = st.text_area("Professional Summary")
    #     experience = st.text_area("Work Experience (provide details of each job including company name, job title, duration, and responsibilities)")
    #     education = st.text_area("Education (provide details of degrees, institutions, and graduation dates)")
    #     skills = st.text_area("Skills (list your skills)")
    #     certifications = st.text_area("Certifications (list any relevant certifications)")
    #     projects = st.text_area("Projects (provide details of your projects)")
        
    #     submitted = st.form_submit_button("Generate Resume")
        
    # if submitted:
    #     if name and contact and linkedin and summary and experience and education and skills and certifications and projects:
    #         details = {
    #             'name': name,
    #             'contact': contact,
    #             'linkedin': linkedin,
    #             'summary': summary,
    #             'experience': experience,
    #             'education': education,
    #             'skills': skills,
    #             'certifications': certifications,
    #             'projects': projects
    #         }
    #         resume = generate_resume(details)
    #         st.header("Generated Resume")
    #         st.text(resume)

    #         # Save resume as PDF and provide download link
    #         pdf_filename = "resume.pdf"
    #         create_pdf(resume, pdf_filename)
            
    #         with open(pdf_filename, "rb") as pdf_file:
    #             st.download_button(
    #                 label="Download Resume as PDF",
    #                 data=pdf_file,
    #                 file_name=pdf_filename,
    #                 mime="application/pdf"
    #             )
    #     else:
    #         st.error("Please fill in all the fields to generate the resume.")