Update app.py
Browse files
app.py
CHANGED
@@ -6,14 +6,13 @@ from weasyprint import HTML
|
|
6 |
from markitdown import MarkItDown
|
7 |
from cerebras.cloud.sdk import Cerebras
|
8 |
|
9 |
-
# Pastikan
|
10 |
-
# atau sesuaikan path 'stylesheets' di fungsi export_resume
|
11 |
|
12 |
# Dapatkan API key dari environment variables
|
13 |
api_key = os.environ.get("CEREBRAS_API_KEY")
|
14 |
|
15 |
-
# Inisialisasi MarkItDown
|
16 |
-
md_converter = MarkItDown()
|
17 |
|
18 |
def create_prompt(resume_string: str, jd_string: str) -> str:
|
19 |
"""
|
@@ -108,16 +107,12 @@ def process_resume(resume, jd_string):
|
|
108 |
Memproses file resume yang di-upload dan job description, lalu
|
109 |
menghasilkan resume yang telah dioptimasi + saran perbaikan.
|
110 |
"""
|
111 |
-
#
|
112 |
-
|
113 |
-
|
114 |
-
# Cek apakah file resume memiliki ekstensi yang didukung
|
115 |
-
if resume.name.lower().endswith(supported_extensions):
|
116 |
-
# Konversi file ke Markdown menggunakan MarkItDown
|
117 |
-
result = md_converter.convert(resume.name)
|
118 |
resume_string = result.text_content # konten Markdown hasil konversi
|
119 |
-
|
120 |
-
return "
|
121 |
|
122 |
# Buat prompt untuk AI
|
123 |
prompt = create_prompt(resume_string, jd_string)
|
@@ -128,6 +123,7 @@ def process_resume(resume, jd_string):
|
|
128 |
# Pisahkan response menjadi "optimized resume" dan "additional suggestions"
|
129 |
response_list = response_string.split("## Additional Suggestions")
|
130 |
new_resume = response_list[0].strip()
|
|
|
131 |
new_resume = re.sub(r'^\* ', '- ', new_resume, flags=re.MULTILINE)
|
132 |
suggestions = "## Additional Suggestions\n\n" + response_list[1].strip() if len(response_list) > 1 else ""
|
133 |
|
@@ -160,7 +156,7 @@ def export_resume(new_resume):
|
|
160 |
menggunakan WeasyPrint.
|
161 |
"""
|
162 |
try:
|
163 |
-
# Konversi Markdown ke HTML
|
164 |
html_content = markdown.markdown(new_resume, extensions=['extra', 'nl2br'])
|
165 |
|
166 |
# Path output PDF
|
@@ -169,7 +165,7 @@ def export_resume(new_resume):
|
|
169 |
# Gunakan stylesheet (pastikan path style.css benar)
|
170 |
HTML(string=html_content).write_pdf(
|
171 |
output_pdf_file,
|
172 |
-
stylesheets=["resumes/style.css"]
|
173 |
)
|
174 |
|
175 |
return output_pdf_file
|
|
|
6 |
from markitdown import MarkItDown
|
7 |
from cerebras.cloud.sdk import Cerebras
|
8 |
|
9 |
+
# Pastikan file style.css tersedia sesuai path (misalnya di folder "resumes" atau di direktori yang sama)
|
|
|
10 |
|
11 |
# Dapatkan API key dari environment variables
|
12 |
api_key = os.environ.get("CEREBRAS_API_KEY")
|
13 |
|
14 |
+
# Inisialisasi MarkItDown dengan semua optional dependencies (pastikan Anda telah menginstal 'markitdown[all]')
|
15 |
+
md_converter = MarkItDown(enable_plugins=True)
|
16 |
|
17 |
def create_prompt(resume_string: str, jd_string: str) -> str:
|
18 |
"""
|
|
|
107 |
Memproses file resume yang di-upload dan job description, lalu
|
108 |
menghasilkan resume yang telah dioptimasi + saran perbaikan.
|
109 |
"""
|
110 |
+
# Gunakan file-like stream dari upload (tanpa cek ekstensi, dukung semua format yang didukung MarkItDown)
|
111 |
+
try:
|
112 |
+
result = md_converter.convert(resume.file)
|
|
|
|
|
|
|
|
|
113 |
resume_string = result.text_content # konten Markdown hasil konversi
|
114 |
+
except Exception as e:
|
115 |
+
return f"Conversion failed: {str(e)}", "", "", "", ""
|
116 |
|
117 |
# Buat prompt untuk AI
|
118 |
prompt = create_prompt(resume_string, jd_string)
|
|
|
123 |
# Pisahkan response menjadi "optimized resume" dan "additional suggestions"
|
124 |
response_list = response_string.split("## Additional Suggestions")
|
125 |
new_resume = response_list[0].strip()
|
126 |
+
# Ganti tanda asterisk di awal baris menjadi tanda "-" untuk bullet list standar
|
127 |
new_resume = re.sub(r'^\* ', '- ', new_resume, flags=re.MULTILINE)
|
128 |
suggestions = "## Additional Suggestions\n\n" + response_list[1].strip() if len(response_list) > 1 else ""
|
129 |
|
|
|
156 |
menggunakan WeasyPrint.
|
157 |
"""
|
158 |
try:
|
159 |
+
# Konversi Markdown ke HTML dengan ekstensi tambahan agar format terjaga
|
160 |
html_content = markdown.markdown(new_resume, extensions=['extra', 'nl2br'])
|
161 |
|
162 |
# Path output PDF
|
|
|
165 |
# Gunakan stylesheet (pastikan path style.css benar)
|
166 |
HTML(string=html_content).write_pdf(
|
167 |
output_pdf_file,
|
168 |
+
stylesheets=["resumes/style.css"]
|
169 |
)
|
170 |
|
171 |
return output_pdf_file
|