Update app.py
Browse files
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 |
-
|
92 |
-
|
93 |
-
|
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 |
-
|
104 |
-
|
105 |
-
suggestions = "## Additional Suggestions \n\n" + response_list[1].strip() if len(response_list) > 1 else ""
|
106 |
|
107 |
-
|
108 |
-
|
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 |
-
|
114 |
-
|
115 |
-
|
|
|
116 |
|
117 |
-
|
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 |
-
|
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 |
-
|
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:
|