muhammadsalmanalfaridzi commited on
Commit
888d73b
·
verified ·
1 Parent(s): 6d3506f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -31
app.py CHANGED
@@ -84,56 +84,52 @@ def get_resume_response(prompt: str, api_key: str, model: str = "llama-3.3-70b",
84
  response_string += chunk.choices[0].delta.content or ""
85
  return response_string
86
 
87
- def process_resume(file, jd_string):
88
  """
89
  Process the uploaded resume and job description, optimize it, and return the result.
90
  """
91
  try:
92
- # Check if file is a 'NamedString' and read its content correctly
93
- file_content = file.name # Access the file content via the file's path
94
-
95
- # Convert file to Markdown using MarkItDown
96
- original_md = md_converter.convert(file_content)
97
- original_text = original_md.text_content
98
-
99
- # Save the original resume in Markdown format
100
- original_file_path = "resumes/original_resume.md"
101
- os.makedirs("resumes", exist_ok=True) # Ensure the directory exists
102
- with open(original_file_path, "w", encoding="utf-8") as f:
103
- f.write(original_text)
104
 
105
  # Create optimization prompt
106
- prompt = create_prompt(original_text, jd_string)
107
- response_string = get_resume_response(prompt, api_key)
108
 
109
- # Split response into optimized resume and suggestions
 
110
  response_list = response_string.split("## Additional Suggestions")
 
 
111
  new_resume = response_list[0].strip()
112
- suggestions = "## Additional Suggestions\n\n" + response_list[1].strip() if len(response_list) > 1 else ""
113
 
114
- # Save the optimized resume in Markdown format
115
  optimized_file_path = "resumes/optimized_resume.md"
 
116
  with open(optimized_file_path, "w", encoding="utf-8") as f:
117
  f.write(new_resume)
118
 
119
- return original_text, new_resume, original_file_path, optimized_file_path, suggestions
 
120
  except Exception as e:
121
- return f"Error processing file: {str(e)}", "", None, None, ""
122
 
123
- def export_resume(md_file_path):
124
- """
125
- Export the optimized resume (in Markdown format) as a PDF file.
126
  """
127
- try:
128
- # Step 1: Convert the file to Markdown using MarkItDown
129
- md_converter = MarkItDown()
130
- result = md_converter.convert(md_file_path)
131
- md_content = result.text_content # This contains the converted Markdown
132
 
133
- # Step 2: Convert Markdown to HTML
134
- html_content = markdown.markdown(md_content) # Using markdown library to convert to HTML
135
 
136
- # Step 3: Convert HTML to PDF using WeasyPrint
 
 
 
 
 
 
 
137
  output_pdf_file = "resumes/optimized_resume.pdf"
138
  os.makedirs("resumes", exist_ok=True) # Ensure the directory exists
139
  HTML(string=html_content).write_pdf(output_pdf_file, stylesheets=['resumes/style.css'])
 
84
  response_string += chunk.choices[0].delta.content or ""
85
  return response_string
86
 
87
+ def process_resume(resume, jd_string):
88
  """
89
  Process the uploaded resume and job description, optimize it, and return the result.
90
  """
91
  try:
92
+ # Read file content from the resume path
93
+ with open(resume.name, "r", encoding="utf-8") as file:
94
+ resume_string = file.read()
 
 
 
 
 
 
 
 
 
95
 
96
  # Create optimization prompt
97
+ prompt = create_prompt(resume_string, jd_string)
 
98
 
99
+ # Generate response using AI
100
+ response_string = get_resume_response(prompt, api_key)
101
  response_list = response_string.split("## Additional Suggestions")
102
+
103
+ # Extract new resume and suggestions for improvement
104
  new_resume = response_list[0].strip()
105
+ suggestions = "## Additional Suggestions \n\n" + response_list[1].strip() if len(response_list) > 1 else ""
106
 
107
+ # Save the optimized resume
108
  optimized_file_path = "resumes/optimized_resume.md"
109
+ os.makedirs("resumes", exist_ok=True) # Ensure the directory exists
110
  with open(optimized_file_path, "w", encoding="utf-8") as f:
111
  f.write(new_resume)
112
 
113
+ # Return the results
114
+ return resume_string, new_resume, optimized_file_path, suggestions
115
  except Exception as e:
116
+ return f"Error processing file: {str(e)}", "", None, ""
117
 
118
+ def export_resume(new_resume):
 
 
119
  """
120
+ Convert a markdown resume to PDF format and save it.
 
 
 
 
121
 
122
+ Args:
123
+ new_resume (str): The resume content in markdown format
124
 
125
+ Returns:
126
+ str: A message indicating success or failure of the PDF export
127
+ """
128
+ try:
129
+ # Convert Markdown to HTML
130
+ html_content = markdown.markdown(new_resume)
131
+
132
+ # Convert HTML to PDF and save
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'])