Spaces:
Sleeping
Sleeping
Update app_logic.py
Browse files- app_logic.py +12 -7
app_logic.py
CHANGED
@@ -62,9 +62,11 @@ def load_token_from_image_and_set_env(image_pil_object: Image.Image, password: s
|
|
62 |
|
63 |
|
64 |
|
|
|
|
|
65 |
def process_commented_markdown(commented_input):
|
66 |
-
"""Process a commented markdown string by stripping '# ' from
|
67 |
-
# Check for '# # Space:' or '# Space:'
|
68 |
if not re.search(r'^\s*#+\s*Space:', commented_input, re.MULTILINE):
|
69 |
return commented_input
|
70 |
|
@@ -73,15 +75,18 @@ def process_commented_markdown(commented_input):
|
|
73 |
in_code_block = False
|
74 |
|
75 |
for line in lines:
|
76 |
-
# Detect code block boundaries
|
77 |
-
if line.strip()
|
78 |
in_code_block = not in_code_block
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
# Strip '# ' from
|
81 |
cleaned_line = line.lstrip("# ")
|
82 |
|
83 |
-
#
|
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 |
|
|
|
62 |
|
63 |
|
64 |
|
65 |
+
import re
|
66 |
+
|
67 |
def process_commented_markdown(commented_input):
|
68 |
+
"""Process a commented markdown string by stripping '# ' from lines where present if '# # Space:' is detected."""
|
69 |
+
# Check for '# # Space:' or '# Space:' to identify a space definition
|
70 |
if not re.search(r'^\s*#+\s*Space:', commented_input, re.MULTILINE):
|
71 |
return commented_input
|
72 |
|
|
|
75 |
in_code_block = False
|
76 |
|
77 |
for line in lines:
|
78 |
+
# Detect code block boundaries (handle both '# ```' and '```')
|
79 |
+
if line.strip() in ("# ```", "```"):
|
80 |
in_code_block = not in_code_block
|
81 |
+
# Preserve backticks as-is (strip '# ' if present)
|
82 |
+
cleaned_line = line.lstrip("# ").rstrip()
|
83 |
+
cleaned_lines.append(cleaned_line)
|
84 |
+
continue
|
85 |
|
86 |
+
# Strip '# ' from lines that have it
|
87 |
cleaned_line = line.lstrip("# ")
|
88 |
|
89 |
+
# In code blocks, remove additional '# ' if present (handles Gemini's over-commenting)
|
|
|
90 |
if in_code_block and cleaned_line.startswith("# "):
|
91 |
cleaned_line = cleaned_line[2:]
|
92 |
|