Ibrahemqasim commited on
Commit
8dc5272
·
verified ·
1 Parent(s): f9d9bad

Create fix langlinks.py

Browse files
Files changed (1) hide show
  1. fix langlinks.py +42 -0
fix langlinks.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import tqdm
3
+ import json
4
+ import requests
5
+ from huggingface_hub import login
6
+ from huggingface_hub import upload_file
7
+
8
+ # تسجيل الدخول إلى Hugging Face (استبدل "YOUR_ACCESS_TOKEN" بالتوكن الخاص بك)
9
+ login("YOUR_ACCESS_TOKEN")
10
+
11
+ # تحميل الملف JSON من الرابط مباشرة
12
+ json_url = "https://huggingface.co/Ibrahemqasim/enwiki_to_arwiki_categories/resolve/main/langlinks.json"
13
+ response = requests.get(json_url)
14
+ data = response.json()
15
+
16
+ # تحويل القاموس إلى قائمة من القواميس [{ "en": "value", "ar": "value" }, ...]
17
+ data_list = []
18
+ for key, value in tqdm.tqdm(data.items()):
19
+ # "Category:1. FC Köln non-playing staff"
20
+ # remove " from start and end
21
+ # ---
22
+ if key.startswith('"') and key.endswith('"'):
23
+ key = key[1:-1]
24
+ # ----
25
+ # remove (:") from start and remove (",) from end
26
+ # :"cc",
27
+ if value.startswith(':"') and value.endswith('",'):
28
+ value = value[2:-2]
29
+ # ----
30
+ data_list.append({"en": key, "ar": value})
31
+
32
+ # حفظ القاموس المصحح في ملف JSON
33
+ with open("langlinks_fixed.json", "w", encoding="utf-8") as f:
34
+ json.dump(data_list, f, ensure_ascii=False, indent=4)
35
+
36
+
37
+ upload_file(
38
+ path_or_fileobj="langlinks_fixed.json", # اسم الملف الذي تم حفظه
39
+ path_in_repo="langlinks_fixed.json", # المسار داخل المستودع
40
+ repo_id="Ibrahemqasim/enwiki_to_arwiki_categories", # معرف المستودع
41
+ # repo_type="dataset", # نوع المستودع (نستخدم dataset للملفات)
42
+ )