Spaces:
Running
Running
Fix ai_ext.py fallback: return empty instead of echoing prompt
Browse files
ai_ext.py
CHANGED
|
@@ -174,39 +174,9 @@ async def qwen_generate(prompt: str, image_url: str = None, max_tokens: int = 12
|
|
| 174 |
|
| 175 |
|
| 176 |
def _fallback_summary_from_prompt(prompt: str, max_units: int = 6) -> str:
|
| 177 |
-
"""Generate a simple fallback summary when AI is unavailable.
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
if marker in text:
|
| 181 |
-
text = text.split(marker, 1)[1]
|
| 182 |
-
break
|
| 183 |
-
text = re.sub(r"https?://\S+", "", text)
|
| 184 |
-
text = re.sub(r"\s+", " ", text).strip()
|
| 185 |
-
|
| 186 |
-
# Split into sentences - extract ALL valid sentences, not just first few
|
| 187 |
-
sentences = re.split(r"(?<=[.!?])\s+(?=[A-ZÀ-Ỹ0-9])", text)
|
| 188 |
-
units = []
|
| 189 |
-
for s in sentences:
|
| 190 |
-
s = _clean_text(s)
|
| 191 |
-
if len(s) >= 30: # Lower threshold to capture more content
|
| 192 |
-
units.append(s)
|
| 193 |
-
|
| 194 |
-
if units:
|
| 195 |
-
# Take up to max_units valid sentences
|
| 196 |
-
result_units = units[:max_units]
|
| 197 |
-
return "\n".join("• " + u for u in result_units)
|
| 198 |
-
if text:
|
| 199 |
-
# Fallback: take chunks if no sentence boundaries found
|
| 200 |
-
chunks = []
|
| 201 |
-
for i in range(0, min(len(text), max_units * 300), 280):
|
| 202 |
-
chunk = _clean_text(text[i:i+300])
|
| 203 |
-
if chunk and chunk not in chunks:
|
| 204 |
-
chunks.append(chunk)
|
| 205 |
-
if len(chunks) >= max_units:
|
| 206 |
-
break
|
| 207 |
-
if chunks:
|
| 208 |
-
return "\n".join("• " + c for c in chunks)
|
| 209 |
-
return "• Không có đủ nội dung để tóm tắt."
|
| 210 |
|
| 211 |
|
| 212 |
HF_TOKEN = _hf_token()
|
|
|
|
| 174 |
|
| 175 |
|
| 176 |
def _fallback_summary_from_prompt(prompt: str, max_units: int = 6) -> str:
|
| 177 |
+
"""Generate a simple fallback summary when AI is unavailable.
|
| 178 |
+
Returns empty string so callers can provide their own fallback."""
|
| 179 |
+
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
|
| 182 |
HF_TOKEN = _hf_token()
|