muhammadsalmanalfaridzi commited on
Commit
ef396f3
·
verified ·
1 Parent(s): 28634dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -88,14 +88,15 @@ def get_resume_response(prompt: str, api_key: str, model: str = "llama-3.3-70b",
88
  return response_string
89
 
90
  def process_resume(file, jd_string):
91
- # Initialize MarkItDown
92
- md = MarkItDown()
 
93
  try:
94
- # Convert file to Markdown
95
- original_md = md.convert(file.name)
96
  original_text = original_md.text_content
97
 
98
- # Save the original Markdown to a file
99
  original_file_path = "resumes/original_resume.md"
100
  with open(original_file_path, "w", encoding="utf-8") as f:
101
  f.write(original_text)
@@ -104,18 +105,19 @@ def process_resume(file, jd_string):
104
  prompt = create_prompt(original_text, jd_string)
105
  response_string = get_resume_response(prompt, api_key)
106
 
107
- # Extract optimized resume and suggestions
108
  response_list = response_string.split("## Additional Suggestions")
109
- new_resume = response_list[0]
 
110
 
111
- # Save the optimized Markdown to a file
112
  optimized_file_path = "resumes/optimized_resume.md"
113
  with open(optimized_file_path, "w", encoding="utf-8") as f:
114
  f.write(new_resume)
115
 
116
- return original_text, new_resume, "resumes/original_resume.md", "resumes/optimized_resume.md"
117
  except Exception as e:
118
- return f"Error processing file: {str(e)}", "", None, None
119
 
120
  def export_resume(new_resume):
121
  try:
@@ -151,7 +153,11 @@ with gr.Blocks() as app:
151
  export_result = gr.Markdown(label="Export Result")
152
 
153
  # Bindings
154
- run_button.click(process_resume, inputs=[resume_input, jd_input], outputs=[before_md, after_md, download_before, download_after, output_suggestions])
 
 
 
 
155
  export_button.click(export_resume, inputs=[after_md], outputs=[export_result])
156
 
157
  app.launch()
 
88
  return response_string
89
 
90
  def process_resume(file, jd_string):
91
+ """
92
+ Process the uploaded resume and job description, optimize it, and return the result.
93
+ """
94
  try:
95
+ # Convert file to Markdown using MarkItDown
96
+ original_md = md_converter.convert(file.name)
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
  with open(original_file_path, "w", encoding="utf-8") as f:
102
  f.write(original_text)
 
105
  prompt = create_prompt(original_text, jd_string)
106
  response_string = get_resume_response(prompt, api_key)
107
 
108
+ # Split response into optimized resume and suggestions
109
  response_list = response_string.split("## Additional Suggestions")
110
+ new_resume = response_list[0].strip()
111
+ suggestions = "## Additional Suggestions\n\n" + response_list[1].strip() if len(response_list) > 1 else ""
112
 
113
+ # Save the optimized resume in Markdown format
114
  optimized_file_path = "resumes/optimized_resume.md"
115
  with open(optimized_file_path, "w", encoding="utf-8") as f:
116
  f.write(new_resume)
117
 
118
+ return original_text, new_resume, original_file_path, optimized_file_path, suggestions
119
  except Exception as e:
120
+ return f"Error processing file: {str(e)}", "", None, None, ""
121
 
122
  def export_resume(new_resume):
123
  try:
 
153
  export_result = gr.Markdown(label="Export Result")
154
 
155
  # Bindings
156
+ run_button.click(
157
+ process_resume,
158
+ inputs=[resume_input, jd_input],
159
+ outputs=[before_md, after_md, download_before, download_after, output_suggestions]
160
+ )
161
  export_button.click(export_resume, inputs=[after_md], outputs=[export_result])
162
 
163
  app.launch()