Spaces:
Sleeping
Sleeping
Update app_logic.py
Browse files- app_logic.py +25 -8
app_logic.py
CHANGED
@@ -61,16 +61,33 @@ def load_token_from_image_and_set_env(image_pil_object: Image.Image, password: s
|
|
61 |
return "\n".join(status_messages_display)
|
62 |
|
63 |
|
|
|
64 |
def process_commented_markdown(commented_input):
|
65 |
-
"""Process a commented markdown string by stripping '# ' from each line if it
|
66 |
-
# Check for '# # Space:'
|
67 |
-
if re.search(r'^\s*#+\s*Space:', commented_input, re.MULTILINE):
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
|
|
74 |
|
75 |
# --- `parse_markdown` (Unchanged from previous corrected version) ---
|
76 |
def parse_markdown(markdown_input):
|
|
|
61 |
return "\n".join(status_messages_display)
|
62 |
|
63 |
|
64 |
+
|
65 |
def process_commented_markdown(commented_input):
|
66 |
+
"""Process a commented markdown string by stripping '# ' from each line if it contains '# # Space:'."""
|
67 |
+
# Check for '# # Space:' or '# Space:' in the input
|
68 |
+
if not re.search(r'^\s*#+\s*Space:', commented_input, re.MULTILINE):
|
69 |
+
return commented_input
|
70 |
+
|
71 |
+
lines = commented_input.strip().split("\n")
|
72 |
+
cleaned_lines = []
|
73 |
+
in_code_block = False
|
74 |
+
|
75 |
+
for line in lines:
|
76 |
+
# Detect code block boundaries
|
77 |
+
if line.strip().startswith("# ```"):
|
78 |
+
in_code_block = not in_code_block
|
79 |
+
|
80 |
+
# Strip '# ' from the start of each line
|
81 |
+
cleaned_line = line.lstrip("# ")
|
82 |
+
|
83 |
+
# If in a code block and the line still starts with '# ', remove it
|
84 |
+
# This handles Gemini's over-commenting within code blocks
|
85 |
+
if in_code_block and cleaned_line.startswith("# "):
|
86 |
+
cleaned_line = cleaned_line[2:]
|
87 |
+
|
88 |
+
cleaned_lines.append(cleaned_line)
|
89 |
|
90 |
+
return "\n".join(cleaned_lines)
|
91 |
|
92 |
# --- `parse_markdown` (Unchanged from previous corrected version) ---
|
93 |
def parse_markdown(markdown_input):
|