Spaces:
Sleeping
Sleeping
Update app_logic.py
Browse files- app_logic.py +17 -6
app_logic.py
CHANGED
@@ -63,12 +63,22 @@ def load_token_from_image_and_set_env(image_pil_object: Image.Image, password: s
|
|
63 |
|
64 |
|
65 |
def process_commented_markdown(commented_input):
|
66 |
-
"""Process a commented markdown string by stripping '# ' from lines
|
67 |
-
#
|
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 |
|
@@ -76,6 +86,7 @@ def process_commented_markdown(commented_input):
|
|
76 |
# Detect code block boundaries (handle '# ```' or '```')
|
77 |
if line.strip() in ("# ```", "```"):
|
78 |
in_code_block = not in_code_block
|
|
|
79 |
cleaned_line = line.lstrip("# ").rstrip()
|
80 |
cleaned_lines.append(cleaned_line)
|
81 |
continue
|
@@ -83,7 +94,7 @@ def process_commented_markdown(commented_input):
|
|
83 |
# Strip '# ' from lines that have it
|
84 |
cleaned_line = line.lstrip("# ")
|
85 |
|
86 |
-
# In code blocks, remove additional '# ' if present (handles over-commenting)
|
87 |
if in_code_block and cleaned_line.startswith("# "):
|
88 |
cleaned_line = cleaned_line[2:]
|
89 |
|
|
|
63 |
|
64 |
|
65 |
def process_commented_markdown(commented_input):
|
66 |
+
"""Process a commented markdown string by stripping '# ' from lines only if '# # Space:' is detected as the first non-empty line."""
|
67 |
+
# Strip leading/trailing whitespace and split lines
|
|
|
|
|
|
|
68 |
lines = commented_input.strip().split("\n")
|
69 |
+
|
70 |
+
# Find the first non-empty line to check for '# # Space:'
|
71 |
+
for line in lines:
|
72 |
+
if line.strip():
|
73 |
+
first_non_empty_line = line.strip()
|
74 |
+
break
|
75 |
+
else:
|
76 |
+
return commented_input # No non-empty lines, return unchanged
|
77 |
+
|
78 |
+
# Only process if the first non-empty line is exactly '# # Space: ...'
|
79 |
+
if not first_non_empty_line.startswith("# # Space:"):
|
80 |
+
return commented_input # Not a commented space definition, return unchanged
|
81 |
+
|
82 |
cleaned_lines = []
|
83 |
in_code_block = False
|
84 |
|
|
|
86 |
# Detect code block boundaries (handle '# ```' or '```')
|
87 |
if line.strip() in ("# ```", "```"):
|
88 |
in_code_block = not in_code_block
|
89 |
+
# Preserve backticks, strip '# ' if present
|
90 |
cleaned_line = line.lstrip("# ").rstrip()
|
91 |
cleaned_lines.append(cleaned_line)
|
92 |
continue
|
|
|
94 |
# Strip '# ' from lines that have it
|
95 |
cleaned_line = line.lstrip("# ")
|
96 |
|
97 |
+
# In code blocks, remove additional '# ' if present (handles over-commenting, e.g., Gemini)
|
98 |
if in_code_block and cleaned_line.startswith("# "):
|
99 |
cleaned_line = cleaned_line[2:]
|
100 |
|