muhammadsalmanalfaridzi commited on
Commit
98e28e8
·
verified ·
1 Parent(s): 430da15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -37
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import os
2
- from cerebras.cloud.sdk import Cerebras
3
  from markitdown import MarkItDown
 
4
  from weasyprint import HTML
5
  import markdown
6
  import gradio as gr
@@ -88,55 +88,34 @@ 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() if len(response_list) > 0 else ""
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
- # Prepare the download links
114
- download_before = resume.name
115
- download_after = optimized_file_path
 
116
 
117
- # Return the results (ensure five outputs)
118
- return resume_string, new_resume, download_before, download_after, suggestions
119
- except Exception as e:
120
- return f"Error processing file: {str(e)}", "", "", "", ""
121
 
122
  def export_resume(new_resume):
123
  """
124
- Convert a markdown resume to PDF format and save it.
125
-
126
- Args:
127
- new_resume (str): The resume content in markdown format
128
-
129
- Returns:
130
- str: A message indicating success or failure of the PDF export
131
  """
132
  try:
133
  # Convert Markdown to HTML
134
  html_content = markdown.markdown(new_resume)
135
-
136
  # Convert HTML to PDF and save
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'])
140
 
141
  return output_pdf_file # Return the file path for download
142
  except Exception as e:
 
1
  import os
 
2
  from markitdown import MarkItDown
3
+ from cerebras.cloud.sdk import Cerebras
4
  from weasyprint import HTML
5
  import markdown
6
  import gradio as gr
 
88
  """
89
  Process the uploaded resume and job description, optimize it, and return the result.
90
  """
91
+ # Convert file to Markdown using MarkItDown
92
+ result = md_converter.convert(resume.name)
93
+ resume_string = result.text_content # Get the converted Markdown content
 
 
 
 
 
 
 
 
94
 
95
+ # Create optimization prompt
96
+ prompt = create_prompt(resume_string, jd_string)
 
97
 
98
+ # Generate response from AI
99
+ response_string = get_resume_response(prompt, api_key)
 
 
 
100
 
101
+ # Split response into optimized resume and suggestions
102
+ response_list = response_string.split("## Additional Suggestions")
103
+ new_resume = response_list[0].strip()
104
+ suggestions = "## Additional Suggestions\n\n" + response_list[1].strip() if len(response_list) > 1 else ""
105
 
106
+ return resume_string, new_resume, suggestions
 
 
 
107
 
108
  def export_resume(new_resume):
109
  """
110
+ Export the optimized resume (in Markdown format) as a PDF file.
 
 
 
 
 
 
111
  """
112
  try:
113
  # Convert Markdown to HTML
114
  html_content = markdown.markdown(new_resume)
115
+
116
  # Convert HTML to PDF and save
117
  output_pdf_file = "resumes/optimized_resume.pdf"
118
+ HTML(string=html_content).write_pdf(output_pdf_file)
 
119
 
120
  return output_pdf_file # Return the file path for download
121
  except Exception as e: