pktpaulie Anushkabhat9 commited on
Commit
eddb386
·
verified ·
1 Parent(s): ea2e593

Update app.py (#3)

Browse files

- Update app.py (ee7f27ad4a494916f37e9e642ba04ce1ead2417f)


Co-authored-by: Anushka Bhat <[email protected]>

Files changed (1) hide show
  1. app.py +36 -2
app.py CHANGED
@@ -304,7 +304,19 @@ def display_doc_as_image2(pdf_path):
304
  """
305
  st.markdown(iframe_code, unsafe_allow_html=True)
306
 
307
-
 
 
 
 
 
 
 
 
 
 
 
 
308
 
309
  # Process if files are uploaded
310
  if uploaded_resume and uploaded_job_description:
@@ -359,7 +371,29 @@ if uploaded_resume and uploaded_job_description:
359
  # st.markdown("---")
360
  st.title("Uploaded Resume")
361
  doc = Document()
362
- doc.add_paragraph(generated_resume)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
364
  # Save the generated document as a .docx file in memory
365
  resume_bytes = BytesIO()
 
304
  """
305
  st.markdown(iframe_code, unsafe_allow_html=True)
306
 
307
+ def add_bold_and_normal_text(paragraph, text):
308
+ """Adds text to the paragraph, handling bold formatting."""
309
+ while "**" in text:
310
+ before, bold_part, after = text.partition("**")
311
+ if before:
312
+ paragraph.add_run(before)
313
+ if bold_part == "**":
314
+ bold_text, _, text = after.partition("**")
315
+ paragraph.add_run(bold_text).bold = True
316
+ else:
317
+ text = after
318
+ if text:
319
+ paragraph.add_run(text)
320
 
321
  # Process if files are uploaded
322
  if uploaded_resume and uploaded_job_description:
 
371
  # st.markdown("---")
372
  st.title("Uploaded Resume")
373
  doc = Document()
374
+
375
+ # Split the text into lines for processing
376
+ lines = generated_resume.splitlines()
377
+
378
+ for line in lines:
379
+ if line.startswith("## "): # Main heading (Level 1)
380
+ paragraph = doc.add_heading(line[3:].strip(), level=1)
381
+ paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.JUSTIFY
382
+ elif line.startswith("### "): # Subheading (Level 2)
383
+ paragraph = doc.add_heading(line[4:].strip(), level=2)
384
+ paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.JUSTIFY
385
+ elif line.startswith("- "): # Bullet points
386
+ paragraph = doc.add_paragraph(style="List Bullet")
387
+ add_bold_and_normal_text(paragraph, line[2:].strip())
388
+ paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.JUSTIFY
389
+ elif line.startswith("* "): # Sub-bullet points or normal list items
390
+ paragraph = doc.add_paragraph(style="List Bullet 2")
391
+ add_bold_and_normal_text(paragraph, line[2:].strip())
392
+ paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.JUSTIFY
393
+ elif line.strip(): # Normal text (ignores blank lines)
394
+ paragraph = doc.add_paragraph()
395
+ add_bold_and_normal_text(paragraph, line.strip())
396
+ paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.JUSTIFY
397
 
398
  # Save the generated document as a .docx file in memory
399
  resume_bytes = BytesIO()