File size: 1,580 Bytes
8dc5272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import re
import tqdm
import json
import requests
from huggingface_hub import login
from huggingface_hub import upload_file

# تسجيل الدخول إلى Hugging Face (استبدل "YOUR_ACCESS_TOKEN" بالتوكن الخاص بك)
login("YOUR_ACCESS_TOKEN")

# تحميل الملف JSON من الرابط مباشرة
json_url = "https://huggingface.co/Ibrahemqasim/enwiki_to_arwiki_categories/resolve/main/langlinks.json"
response = requests.get(json_url)
data = response.json()

# تحويل القاموس إلى قائمة من القواميس [{ "en": "value", "ar": "value" }, ...]
data_list = []
for key, value in tqdm.tqdm(data.items()):
    # "Category:1. FC Köln non-playing staff"
    # remove " from start and end
    # ---
    if key.startswith('"') and key.endswith('"'):
        key = key[1:-1]
    # ----
    # remove (:") from start and remove (",) from end
    # :"cc",
    if value.startswith(':"') and value.endswith('",'):
        value = value[2:-2]
    # ----
    data_list.append({"en": key, "ar": value})

# حفظ القاموس المصحح في ملف JSON
with open("langlinks_fixed.json", "w", encoding="utf-8") as f:
    json.dump(data_list, f, ensure_ascii=False, indent=4)


upload_file(
    path_or_fileobj="langlinks_fixed.json",  # اسم الملف الذي تم حفظه
    path_in_repo="langlinks_fixed.json",  # المسار داخل المستودع
    repo_id="Ibrahemqasim/enwiki_to_arwiki_categories",  # معرف المستودع
    # repo_type="dataset",  # نوع المستودع (نستخدم dataset للملفات)
)