selamw commited on
Commit
fdd8055
·
verified ·
1 Parent(s): 14131e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -14,22 +14,21 @@ bnb_config = BitsAndBytesConfig(load_in_8bit=True)
14
 
15
 
16
  def convert_to_markdown(input_text):
17
- # Split the input text into sections based on the '**' delimiter
18
- sections = input_text.split("**")
19
-
20
- # Initialize the formatted output with the bird name
21
- formatted_output = f"**{sections[0].strip()}**\n"
22
-
23
- # Process each section to format it
24
- for i in range(1, len(sections), 2):
25
- if i + 1 < len(sections):
26
- # Use '##' for subheadings and clean up the text
27
- header = sections[i].strip() + "** "
28
- content = sections[i + 1].strip()
29
- formatted_output += f"\n**{header}{content}\n"
30
-
31
- # Return the formatted output
32
- return formatted_output.strip()
33
 
34
 
35
  @spaces.GPU
 
14
 
15
 
16
  def convert_to_markdown(input_text):
17
+ input_text = input_text.replace("!:", ":")
18
+
19
+ # Find all words before ': **' and replace with bold markdown
20
+ output_text = re.sub(r'(\w+)\s*:\s*\*\*', r'**\1**:', input_text)
21
+
22
+ # Replace double asterisks with double hashtags for remaining headings
23
+ output_text = output_text.replace("**", "##")
24
+
25
+ # Remove any extra whitespace at the beginning of lines
26
+ output_text = re.sub(r'^\s+', '', output_text, flags=re.MULTILINE)
27
+
28
+ # Add an extra newline after each heading (after the colon)
29
+ output_text = "## " + re.sub(r'(##\s*.*):', r'\1:\n\n', output_text)
30
+
31
+ return output_text
 
32
 
33
 
34
  @spaces.GPU