muhammadsalmanalfaridzi commited on
Commit
93fba37
Β·
verified Β·
1 Parent(s): e743ba4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -116,16 +116,24 @@ def process_resume(file, jd_string):
116
  except Exception as e:
117
  return f"Error processing file: {str(e)}", "", None, None, ""
118
 
119
- def export_resume(new_resume):
120
  """
121
- Export the optimized resume as a PDF file.
122
  """
123
  try:
124
- # Save optimized Markdown as PDF
125
- output_pdf_file = "resumes/resume_new.pdf"
 
 
 
 
 
 
 
 
126
  os.makedirs("resumes", exist_ok=True) # Ensure the directory exists
127
- html_content = f"<html><body>{new_resume}</body></html>" # Simple HTML wrapper
128
  HTML(string=html_content).write_pdf(output_pdf_file, stylesheets=['resumes/style.css'])
 
129
  return output_pdf_file # Return the file path for download
130
  except Exception as e:
131
  return f"Failed to export resume: {str(e)} πŸ’”"
 
116
  except Exception as e:
117
  return f"Error processing file: {str(e)}", "", None, None, ""
118
 
119
+ def export_resume(md_file_path):
120
  """
121
+ Export the optimized resume (in Markdown format) as a PDF file.
122
  """
123
  try:
124
+ # Step 1: Convert the file to Markdown using MarkItDown
125
+ md_converter = MarkItDown()
126
+ result = md_converter.convert(md_file_path)
127
+ md_content = result.text_content # This contains the converted Markdown
128
+
129
+ # Step 2: Convert Markdown to HTML
130
+ html_content = markdown.markdown(md_content) # Using markdown library to convert to HTML
131
+
132
+ # Step 3: Convert HTML to PDF using WeasyPrint
133
+ output_pdf_file = "resumes/optimized_resume.pdf"
134
  os.makedirs("resumes", exist_ok=True) # Ensure the directory exists
 
135
  HTML(string=html_content).write_pdf(output_pdf_file, stylesheets=['resumes/style.css'])
136
+
137
  return output_pdf_file # Return the file path for download
138
  except Exception as e:
139
  return f"Failed to export resume: {str(e)} πŸ’”"