RP-Azul commited on
Commit
da9117a
Β·
verified Β·
1 Parent(s): da792ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -8
app.py CHANGED
@@ -13,23 +13,64 @@ if uploaded_file and method != "Select a method":
13
  if method == "Raw Markdown":
14
  st.markdown(markdown_text)
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  elif method == "Boxing Method":
17
  def parse_markdown_into_boxes(text):
18
- pattern = r'(^#+ .*$)'
19
- parts = re.split(pattern, text, flags=re.MULTILINE)
 
 
 
 
 
 
 
 
 
20
  sections = []
21
  for i in range(1, len(parts), 2):
22
  header = parts[i].strip()
23
  content = parts[i + 1].strip() if i + 1 < len(parts) else ""
24
  sections.append({"header": header, "content": content})
25
  return sections
26
-
27
- st.subheader("πŸ“¦ Formatted Output")
28
- for section in parse_markdown_into_boxes(markdown_text):
29
- with st.container(border=True):
30
- if section["header"]:
31
- st.markdown(f"#### {section['header']}")
 
 
 
 
 
 
 
32
  st.markdown(section["content"])
 
 
 
 
 
 
 
 
33
 
34
  # elif method == "Outline Method":
35
  # st.subheader("πŸ“ Outline Method Output")
 
13
  if method == "Raw Markdown":
14
  st.markdown(markdown_text)
15
 
16
+ # elif method == "Boxing Method":
17
+ # def parse_markdown_into_boxes(text):
18
+ # pattern = r'(^#+ .*$)'
19
+ # parts = re.split(pattern, text, flags=re.MULTILINE)
20
+ # sections = []
21
+ # for i in range(1, len(parts), 2):
22
+ # header = parts[i].strip()
23
+ # content = parts[i + 1].strip() if i + 1 < len(parts) else ""
24
+ # sections.append({"header": header, "content": content})
25
+ # return sections
26
+
27
+ # st.subheader("πŸ“¦ Formatted Output")
28
+ # for section in parse_markdown_into_boxes(markdown_text):
29
+ # with st.container(border=True):
30
+ # if section["header"]:
31
+ # st.markdown(f"#### {section['header']}")
32
+ # st.markdown(section["content"])
33
  elif method == "Boxing Method":
34
  def parse_markdown_into_boxes(text):
35
+ # Remove ```markdown block if it exists
36
+ cleaned = text.strip()
37
+ if cleaned.startswith("```markdown"):
38
+ cleaned = cleaned[len("```markdown"):].strip()
39
+ if cleaned.endswith("```"):
40
+ cleaned = cleaned[:-3].strip()
41
+
42
+ # Split based on Markdown headers (## Box or ## Summary)
43
+ pattern = r'(^## .*$)'
44
+ parts = re.split(pattern, cleaned, flags=re.MULTILINE)
45
+
46
  sections = []
47
  for i in range(1, len(parts), 2):
48
  header = parts[i].strip()
49
  content = parts[i + 1].strip() if i + 1 < len(parts) else ""
50
  sections.append({"header": header, "content": content})
51
  return sections
52
+
53
+ st.subheader("πŸ“¦ Boxing Method Output")
54
+
55
+ all_sections = parse_markdown_into_boxes(markdown_text)
56
+ boxes = [s for s in all_sections if not s["header"].lower().startswith("## summary")]
57
+ summary = next((s for s in all_sections if s["header"].lower().startswith("## summary")), None)
58
+
59
+ # Display boxes in two columns
60
+ col1, col2 = st.columns(2)
61
+ for i, section in enumerate(boxes):
62
+ target_col = col1 if i % 2 == 0 else col2
63
+ with target_col.container(border=True):
64
+ st.markdown(f"#### {section['header']}")
65
  st.markdown(section["content"])
66
+
67
+ # Display summary below full width
68
+ if summary:
69
+ st.markdown("---")
70
+ with st.container(border=True):
71
+ st.markdown(f"### {summary['header']}")
72
+ st.markdown(summary['content'])
73
+
74
 
75
  # elif method == "Outline Method":
76
  # st.subheader("πŸ“ Outline Method Output")