Spaces:
Running
Running
Upload ai_patch.py with huggingface_hub
Browse files- ai_patch.py +8 -1
ai_patch.py
CHANGED
|
@@ -22,7 +22,9 @@ except Exception:
|
|
| 22 |
|
| 23 |
def _clean(s):
|
| 24 |
s = html_lib.unescape(s or "")
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
s = re.sub(r"\n{3,}", "\n\n", s)
|
| 27 |
return s.strip()
|
| 28 |
|
|
@@ -64,6 +66,11 @@ def _postprocess_ai_text(text, max_units=20):
|
|
| 64 |
text = _clean(text)
|
| 65 |
if not text:
|
| 66 |
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
drop_prefixes = (
|
| 68 |
"dưới đây", "sau đây", "bài viết", "tôi sẽ", "mình sẽ",
|
| 69 |
"tóm tắt bài", "tiêu đề:", "sapo:", "nội dung:", "kết luận:"
|
|
|
|
| 22 |
|
| 23 |
def _clean(s):
|
| 24 |
s = html_lib.unescape(s or "")
|
| 25 |
+
# Remove HTML tags like <a href=...>, <img src=...>
|
| 26 |
+
s = re.sub(r'<[^>]+>', '', s)
|
| 27 |
+
s = re.sub(r"\s+", " ", s)
|
| 28 |
s = re.sub(r"\n{3,}", "\n\n", s)
|
| 29 |
return s.strip()
|
| 30 |
|
|
|
|
| 66 |
text = _clean(text)
|
| 67 |
if not text:
|
| 68 |
return text
|
| 69 |
+
# Remove any remaining HTML artifacts like <a href='...'>, <img src=...> even if partially corrupted
|
| 70 |
+
text = re.sub(r'<a\s+[^>]*>', '', text, flags=re.I)
|
| 71 |
+
text = re.sub(r'<img\s+[^>]*>', '', text, flags=re.I)
|
| 72 |
+
text = re.sub(r'</a>', '', text, flags=re.I)
|
| 73 |
+
text = re.sub(r'<[^>]+>', '', text) # Any remaining HTML tags
|
| 74 |
drop_prefixes = (
|
| 75 |
"dưới đây", "sau đây", "bài viết", "tôi sẽ", "mình sẽ",
|
| 76 |
"tóm tắt bài", "tiêu đề:", "sapo:", "nội dung:", "kết luận:"
|