to-164
This commit is contained in:
Executable
+88
@@ -0,0 +1,88 @@
|
||||
import os
|
||||
import json
|
||||
import orjson
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from ._prompt import SYS_PROMPT
|
||||
|
||||
def load_orjson(path: str | Path):
|
||||
path = Path(path)
|
||||
with path.open("rb") as f: # باید باینری باز بشه برای orjson
|
||||
return orjson.loads(f.read())
|
||||
|
||||
|
||||
def save_orjson(path, data):
|
||||
with open(path, "wb") as f:
|
||||
f.write(
|
||||
orjson.dumps(data, option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS)
|
||||
)
|
||||
|
||||
|
||||
def make_data(all_data, system_prompt, assistant_prompt=None):
|
||||
api_batch = []
|
||||
for item in all_data:
|
||||
|
||||
user_prompt = f"جمله عربی: `{item.get('text')}`"
|
||||
api_batch.append(
|
||||
{
|
||||
"id": str(item.get("id")),
|
||||
"user_prompt": str(user_prompt),
|
||||
"system_prompt": system_prompt,
|
||||
"assistant_prompt": assistant_prompt,
|
||||
}
|
||||
)
|
||||
return api_batch
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# raw_data = load_orjson(
|
||||
# path="/home1/ava3/init_mahdi/project/aiDataParser/task/translate_hadith/hadith100/input/json_hadis.json"
|
||||
# )
|
||||
# # sanad_list = [{'id':item['id'], 'sanad':item['sanad']} for item in raw_data]
|
||||
# text_list = [{'id':item['id'], 'text':item['text']} for item in raw_data]
|
||||
# print(f"raw_data_map {len(raw_data)}")
|
||||
# # print(f"sanad_list {len(sanad_list)}")
|
||||
# print(f"text_list {len(text_list)}")
|
||||
|
||||
# data = make_data(
|
||||
# all_data=text_list, system_prompt=SYS_PROMPT
|
||||
# )
|
||||
|
||||
# save_orjson(
|
||||
# data=data,
|
||||
# path="/home1/ava3/init_mahdi/project/aiDataParser/task/translate_hadith/100_v2/input/arabic_text.json"
|
||||
# )
|
||||
|
||||
#########################################################################################################
|
||||
in_hadis = load_orjson('/home1/ava3/init_mahdi/project/aiDataParser/task/translate_hadith/hadith100/output/finall_json.json')
|
||||
translate_hadis = load_orjson('/home1/ava3/init_mahdi/project/aiDataParser/task/translate_hadith/100_v2/output/final_data_translate-hadith-100-v2-oss-120b.json')
|
||||
in_hadis_dict = {str(item["id"]): item for item in in_hadis}
|
||||
translate_hadis_dict = {str(item["id"]): item for item in translate_hadis}
|
||||
|
||||
|
||||
for i, item in enumerate(in_hadis):
|
||||
id = str(item['id'])
|
||||
tr_hadis = translate_hadis_dict.get(id)
|
||||
|
||||
|
||||
persian_sanad120=" ".join(tr_hadis['persian'])
|
||||
code_sanad120 = tr_hadis['ai_code_version']
|
||||
code_sanad120 ='hadis_v2_'+code_sanad120
|
||||
item[code_sanad120] = persian_sanad120
|
||||
print(f'--- {i}/{len(in_hadis)} -> id {id} ' )
|
||||
|
||||
|
||||
df = pd.DataFrame(in_hadis)
|
||||
|
||||
# ذخیره در فایل اکسل
|
||||
output_path = "/home1/ava3/init_mahdi/project/aiDataParser/task/translate_hadith/100_v2/finall_hadith_v2_excel.xlsx"
|
||||
df.to_excel(output_path, index=False, engine="openpyxl")
|
||||
|
||||
print(f"✅ فایل اکسل با موفقیت در {output_path} ذخیره شد.")
|
||||
|
||||
save_orjson(
|
||||
path='/home1/ava3/init_mahdi/project/aiDataParser/task/translate_hadith/100_v2/finall_hadith_v2_json.json',
|
||||
data=in_hadis
|
||||
)
|
||||
# python3 -m aiDataParser.task.translate_hadith.100_v2.data_ready
|
||||
Reference in New Issue
Block a user