Anushkabhat9 commited on
Commit
2a72aac
·
verified ·
1 Parent(s): eb4ebbe

Update resume_generation_gemini_pro.py

Browse files
Files changed (1) hide show
  1. resume_generation_gemini_pro.py +29 -19
resume_generation_gemini_pro.py CHANGED
@@ -31,7 +31,7 @@ Original file is located at
31
 
32
  import docx2txt
33
  import PyPDF2
34
-
35
  def extract_text(file_path):
36
  if file_path.endswith(".docx"):
37
  # Extract text from DOCX file
@@ -53,11 +53,10 @@ def extract_text(file_path):
53
  # auth.authenticate_user()
54
 
55
  import os
56
-
57
- GOOGLE_APPLICATION_CREDENTIALS = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
58
- private_key_id = os.environ.get('PRIVATE_KEY_ID')
59
- private_key = os.environ.get('PRIVATE_KEY')
60
- client_id = os.environ.get('CLIENT_ID')
61
 
62
  # !pip install python-docx
63
 
@@ -85,6 +84,10 @@ def save_resume_to_docx(tailored_resume, file_path):
85
  doc.add_paragraph(tailored_resume)
86
  doc.save(file_path)
87
 
 
 
 
 
88
  # Function to read text from a .docx file
89
  def read_docx(file_path):
90
  doc = Document(file_path)
@@ -122,8 +125,6 @@ Using the candidate's resume above and the job description below, create a tailo
122
  [Job Description Start]
123
  {job_description}
124
  [Job Description End]
125
-
126
-
127
  Please generate a resume that:
128
  1. Uses real data from the candidate's resume, including name, and education.
129
  2. Avoids placeholders like "[Your Name]" and includes actual details. This is important.
@@ -193,24 +194,33 @@ def convert_resume_to_word(markdown_text,output_file):
193
  print(f"Markdown converted and saved as {output_file}")
194
 
195
  #Entry function for the model
196
- def generate_gemini(current_resume,job_description):
197
  st.header('Resume Tailoring')
198
-
199
  # Load the resume and job description from Google Drive
200
  resume_text = extract_text(current_resume)
201
  job_description = extract_text(job_description)
202
 
203
  # Tailor resume based on job description
204
  tailored_resume = tailor_resume(resume_text, job_description)
205
- output_file = f"Tailored_Resume_{datetime.now().strftime('%Y%m%d_%H%M%S')}.docx"
206
- convert_resume_to_word(tailored_resume,output_file)
207
-
208
- st.success(f"Tailored resume saved to {output_file}")
209
- output_text = extract_text(output_file)
210
- st.write(output_text)
211
-
212
- return tailored_resume, output_file
213
-
 
 
 
 
 
 
 
 
 
 
214
 
215
  # Main function for Streamlit app
216
  # def Gemini_pro_main(current_resume,job_description):
 
31
 
32
  import docx2txt
33
  import PyPDF2
34
+ import subprocess
35
  def extract_text(file_path):
36
  if file_path.endswith(".docx"):
37
  # Extract text from DOCX file
 
53
  # auth.authenticate_user()
54
 
55
  import os
56
+ # GOOGLE_APPLICATION_CREDENTIALS = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
57
+ # private_key_id = os.environ.get('PRIVATE_KEY_ID')
58
+ # private_key = os.environ.get('PRIVATE_KEY')
59
+ # client_id = os.environ.get('CLIENT_ID')
 
60
 
61
  # !pip install python-docx
62
 
 
84
  doc.add_paragraph(tailored_resume)
85
  doc.save(file_path)
86
 
87
+ def save_resume_to_pdf(docx_file_path, file_path):
88
+ subprocess.run(['libreoffice', '--headless', '--convert-to', 'pdf', '--outdir', file_path, docx_file_path])
89
+
90
+
91
  # Function to read text from a .docx file
92
  def read_docx(file_path):
93
  doc = Document(file_path)
 
125
  [Job Description Start]
126
  {job_description}
127
  [Job Description End]
 
 
128
  Please generate a resume that:
129
  1. Uses real data from the candidate's resume, including name, and education.
130
  2. Avoids placeholders like "[Your Name]" and includes actual details. This is important.
 
194
  print(f"Markdown converted and saved as {output_file}")
195
 
196
  #Entry function for the model
197
+ def generate_gemini(current_resume,job_description , download_path , doctype):
198
  st.header('Resume Tailoring')
 
199
  # Load the resume and job description from Google Drive
200
  resume_text = extract_text(current_resume)
201
  job_description = extract_text(job_description)
202
 
203
  # Tailor resume based on job description
204
  tailored_resume = tailor_resume(resume_text, job_description)
205
+ st.write("**Tailored Resume:**")
206
+ st.write(tailored_resume)
207
+ print(tailored_resume)
208
+
209
+ # Save the tailored resume to a .docx file
210
+ if tailored_resume:
211
+ time = datetime.now().strftime('%Y%m%d_%H%M%S')
212
+ file_name = f"Tailored_Resume_{time}.docx"
213
+ file_path = os.path.join(download_path , file_name)
214
+ convert_resume_to_word(tailored_resume,file_path)
215
+ if(doctype == 'pdf'):
216
+ file_name = f"Tailored_Resume_{time}.pdf"
217
+ save_resume_to_pdf(file_path, download_path)
218
+ file_path = os.path.join(download_path , file_name)
219
+
220
+ st.success(f"Download tailored resume")
221
+ # st.success(f"Tailored resume saved to {file_path}")
222
+
223
+ return tailored_resume, file_path
224
 
225
  # Main function for Streamlit app
226
  # def Gemini_pro_main(current_resume,job_description):