Update app.py
Browse files
app.py
CHANGED
@@ -5,15 +5,13 @@ import gradio as gr
|
|
5 |
from weasyprint import HTML
|
6 |
from markitdown import MarkItDown
|
7 |
from cerebras.cloud.sdk import Cerebras
|
8 |
-
import tempfile
|
9 |
|
10 |
# Pastikan file style.css tersedia sesuai path (misalnya di folder "resumes" atau di direktori yang sama)
|
11 |
|
12 |
# Dapatkan API key dari environment variables
|
13 |
api_key = os.environ.get("CEREBRAS_API_KEY")
|
14 |
|
15 |
-
# Inisialisasi MarkItDown dengan semua optional dependencies
|
16 |
-
# (Pastikan Anda telah menginstal 'markitdown[all]~=0.1.0a1')
|
17 |
md_converter = MarkItDown(enable_plugins=True)
|
18 |
|
19 |
def create_prompt(resume_string: str, jd_string: str) -> str:
|
@@ -109,27 +107,10 @@ def process_resume(resume, jd_string):
|
|
109 |
Memproses file resume yang di-upload dan job description, lalu
|
110 |
menghasilkan resume yang telah dioptimasi + saran perbaikan.
|
111 |
"""
|
112 |
-
#
|
113 |
try:
|
114 |
-
|
115 |
-
if hasattr(resume, "file"):
|
116 |
-
file_obj = resume.file
|
117 |
-
# Jika resume adalah dictionary, coba ambil key "file"
|
118 |
-
elif isinstance(resume, dict) and "file" in resume:
|
119 |
-
file_obj = resume["file"]
|
120 |
-
else:
|
121 |
-
return "Uploaded file tidak valid.", "", "", "", ""
|
122 |
-
|
123 |
-
# Sebagai langkah tambahan, simpan file ke file sementara (tempfile) untuk memastikan bukan direktori
|
124 |
-
with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
125 |
-
tmp.write(file_obj.read())
|
126 |
-
tmp_path = tmp.name
|
127 |
-
|
128 |
-
result = md_converter.convert(tmp_path)
|
129 |
resume_string = result.text_content # konten Markdown hasil konversi
|
130 |
-
|
131 |
-
# Hapus file sementara
|
132 |
-
os.remove(tmp_path)
|
133 |
except Exception as e:
|
134 |
return f"Conversion failed: {str(e)}", "", "", "", ""
|
135 |
|
@@ -191,70 +172,46 @@ def export_resume(new_resume):
|
|
191 |
except Exception as e:
|
192 |
return f"Failed to export resume: {str(e)} π"
|
193 |
|
194 |
-
# Fitur Preview dan Editor Langsung (Tambahan)
|
195 |
-
def update_preview(resume_text: str) -> str:
|
196 |
-
"""
|
197 |
-
Fungsi sederhana yang mengembalikan teks resume sebagai Markdown untuk live preview.
|
198 |
-
"""
|
199 |
-
return resume_text
|
200 |
-
|
201 |
# Bangun aplikasi Gradio
|
202 |
with gr.Blocks() as app:
|
203 |
gr.Markdown("# Resume Optimizer π")
|
204 |
-
gr.Markdown("Upload resume
|
205 |
-
|
206 |
with gr.Row():
|
207 |
-
resume_input = gr.File(label="Upload Your Resume")
|
208 |
jd_input = gr.Textbox(
|
209 |
label="Paste the Job Description Here",
|
210 |
lines=9,
|
211 |
interactive=True,
|
212 |
placeholder="Paste job description..."
|
213 |
)
|
214 |
-
|
215 |
run_button = gr.Button("Optimize Resume π€")
|
216 |
-
|
217 |
with gr.Row():
|
218 |
before_md = gr.Markdown(label="Original Resume (Before)")
|
219 |
after_md = gr.Markdown(label="Optimized Resume (After)")
|
220 |
output_suggestions = gr.Markdown(label="Suggestions")
|
221 |
-
|
222 |
with gr.Row():
|
223 |
download_before = gr.File(label="Download Original Resume")
|
224 |
download_after = gr.File(label="Download Optimized Resume")
|
225 |
-
|
226 |
export_button = gr.Button("Export Optimized Resume as PDF π")
|
227 |
export_result = gr.File(label="Download PDF")
|
228 |
-
|
229 |
-
#
|
230 |
-
gr.Markdown("## Live Resume Editor and Preview")
|
231 |
-
resume_editor = gr.Textbox(
|
232 |
-
lines=20,
|
233 |
-
label="Edit Your Optimized Resume (Markdown Format)",
|
234 |
-
placeholder="Tulis atau edit resume Anda di sini..."
|
235 |
-
)
|
236 |
-
live_preview = gr.Markdown(label="Live Preview")
|
237 |
-
update_button = gr.Button("Update Preview")
|
238 |
-
|
239 |
-
# Binding: Jika tombol Optimize Resume diklik, jalankan process_resume
|
240 |
run_button.click(
|
241 |
process_resume,
|
242 |
inputs=[resume_input, jd_input],
|
243 |
outputs=[before_md, after_md, download_before, download_after, output_suggestions]
|
244 |
)
|
245 |
-
|
246 |
-
#
|
247 |
export_button.click(
|
248 |
export_resume,
|
249 |
inputs=[after_md],
|
250 |
outputs=[export_result]
|
251 |
)
|
252 |
-
|
253 |
-
# Binding untuk fitur live preview: update preview secara otomatis saat editor berubah
|
254 |
-
resume_editor.change(fn=update_preview, inputs=resume_editor, outputs=live_preview)
|
255 |
-
update_button.click(fn=update_preview, inputs=resume_editor, outputs=live_preview)
|
256 |
-
|
257 |
-
# Saat resume setelah optimasi tersedia, isi editor dengan teks tersebut agar bisa diedit lebih lanjut
|
258 |
-
after_md.change(fn=lambda x: x, inputs=after_md, outputs=resume_editor)
|
259 |
|
260 |
app.launch()
|
|
|
5 |
from weasyprint import HTML
|
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:
|
|
|
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 |
|
|
|
172 |
except Exception as e:
|
173 |
return f"Failed to export resume: {str(e)} π"
|
174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
# Bangun aplikasi Gradio
|
176 |
with gr.Blocks() as app:
|
177 |
gr.Markdown("# Resume Optimizer π")
|
178 |
+
gr.Markdown("Upload your resume, paste the job description, and get actionable insights!")
|
179 |
+
|
180 |
with gr.Row():
|
181 |
+
resume_input = gr.File(label="Upload Your Resume")
|
182 |
jd_input = gr.Textbox(
|
183 |
label="Paste the Job Description Here",
|
184 |
lines=9,
|
185 |
interactive=True,
|
186 |
placeholder="Paste job description..."
|
187 |
)
|
188 |
+
|
189 |
run_button = gr.Button("Optimize Resume π€")
|
190 |
+
|
191 |
with gr.Row():
|
192 |
before_md = gr.Markdown(label="Original Resume (Before)")
|
193 |
after_md = gr.Markdown(label="Optimized Resume (After)")
|
194 |
output_suggestions = gr.Markdown(label="Suggestions")
|
195 |
+
|
196 |
with gr.Row():
|
197 |
download_before = gr.File(label="Download Original Resume")
|
198 |
download_after = gr.File(label="Download Optimized Resume")
|
199 |
+
|
200 |
export_button = gr.Button("Export Optimized Resume as PDF π")
|
201 |
export_result = gr.File(label="Download PDF")
|
202 |
+
|
203 |
+
# Saat tombol Optimize Resume diklik
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
run_button.click(
|
205 |
process_resume,
|
206 |
inputs=[resume_input, jd_input],
|
207 |
outputs=[before_md, after_md, download_before, download_after, output_suggestions]
|
208 |
)
|
209 |
+
|
210 |
+
# Saat tombol Export PDF diklik
|
211 |
export_button.click(
|
212 |
export_resume,
|
213 |
inputs=[after_md],
|
214 |
outputs=[export_result]
|
215 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
app.launch()
|