Mazenbs commited on
Commit
e3aa294
·
verified ·
1 Parent(s): bcf8324

Create indexer_simple.py

Browse files
Files changed (1) hide show
  1. helpers/indexer_simple.py +37 -0
helpers/indexer_simple.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List, Dict, Optional
2
+
3
+ def detect_extra_type(text: str) -> Optional[str]:
4
+ """يتعرف على إن كان النص عبارة عن صورة أو رابط."""
5
+ lower = text.lower()
6
+
7
+ # رابط
8
+ if lower.startswith(("http://", "https://")):
9
+ # رابط صورة؟
10
+ if lower.endswith((".jpg", ".jpeg", ".png", ".gif", ".webp")):
11
+ return "image"
12
+ return "link"
13
+
14
+ # base64 image
15
+ if lower.startswith("data:image/"):
16
+ return "image"
17
+
18
+ # ملف صورة بدون رابط
19
+ if lower.endswith((".jpg", ".jpeg", ".png", ".gif", ".webp")):
20
+ return "image"
21
+
22
+ return None
23
+
24
+
25
+ def build_indexed(texts: List[Dict[str, str]]) -> List[Dict[str, str]]:
26
+ """يُعيد القائمة كما هي مع تحديد النوع فقط."""
27
+ if not texts:
28
+ return []
29
+
30
+ result = []
31
+ for item in texts:
32
+ extra_type = detect_extra_type(item["text"])
33
+ result.append({
34
+ "text": item["text"].strip(),
35
+ "type": extra_type if extra_type else "text"
36
+ })
37
+ return result