Spaces:
Sleeping
Sleeping
| from typing import List, Dict, Optional | |
| def detect_extra_type(text: str) -> Optional[str]: | |
| """يتعرف على إن كان النص عبارة عن صورة أو رابط.""" | |
| lower = text.lower() | |
| # رابط | |
| if lower.startswith(("http://", "https://")): | |
| # رابط صورة؟ | |
| if lower.endswith((".jpg", ".jpeg", ".png", ".gif", ".webp")): | |
| return "image" | |
| return "link" | |
| # base64 image | |
| if lower.startswith("data:image/"): | |
| return "image" | |
| # ملف صورة بدون رابط | |
| if lower.endswith((".jpg", ".jpeg", ".png", ".gif", ".webp")): | |
| return "image" | |
| return None | |
| def build_indexed(texts: List[Dict[str, str]]) -> List[Dict[str, str]]: | |
| """يُعيد القائمة كما هي مع تحديد النوع فقط.""" | |
| if not texts: | |
| return [] | |
| result = [] | |
| for item in texts: | |
| extra_type = detect_extra_type(item["text"]) | |
| result.append({ | |
| "value": item["text"].strip(), | |
| "type": extra_type if extra_type else "text" | |
| }) | |
| return result | |