Spaces:
Sleeping
Sleeping
Update core/utils.py
Browse files- core/utils.py +7 -17
core/utils.py
CHANGED
@@ -1,24 +1,14 @@
|
|
1 |
-
#
|
2 |
import re
|
3 |
|
4 |
def basic_text_cleanup(text: str) -> str:
|
5 |
-
|
6 |
-
if not text or not isinstance(text, str):
|
7 |
-
return ""
|
8 |
-
|
9 |
text = text.strip()
|
10 |
-
|
11 |
-
patterns = [
|
12 |
-
r"^```python\s*(.*?)\s*```$", # ```python ... ```
|
13 |
-
r"^```\s*(.*?)\s*```$", # ``` ... ```
|
14 |
-
]
|
15 |
-
|
16 |
for pattern in patterns:
|
17 |
match = re.match(pattern, text, re.DOTALL | re.IGNORECASE)
|
18 |
-
if match:
|
19 |
-
|
20 |
-
|
21 |
-
return text # Return original if no common markers found
|
22 |
|
23 |
-
#
|
24 |
-
print("DEBUG: core.utils - Module defined.")
|
|
|
1 |
+
# storyverse_weaver/core/utils.py
|
2 |
import re
|
3 |
|
4 |
def basic_text_cleanup(text: str) -> str:
|
5 |
+
if not text or not isinstance(text, str): return ""
|
|
|
|
|
|
|
6 |
text = text.strip()
|
7 |
+
patterns = [ r"^```(?:python|text|narrative)?\s*(.*?)\s*```$", r"^```\s*(.*?)\s*```$" ]
|
|
|
|
|
|
|
|
|
|
|
8 |
for pattern in patterns:
|
9 |
match = re.match(pattern, text, re.DOTALL | re.IGNORECASE)
|
10 |
+
if match: return match.group(1).strip()
|
11 |
+
return text
|
|
|
|
|
12 |
|
13 |
+
# Could add image resizing, format conversion utilities here later
|
14 |
+
print("DEBUG: core.utils (for StoryVerseWeaver) - Module defined.")
|