Download write_back.py from yilunzhao/rprp: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/datasets/yilunzhao/rprp/resolve/main/write_back.py
- Command line
-
hf download hf://datasets/yilunzhao/rprp/write_back.py
-
curl -L -o write_back.py https://huggingface.co/datasets/yilunzhao/rprp/resolve/main/write_back.py
1.08 kB
| import os | |
| import json | |
| from tqdm import tqdm | |
| # 要遍历的目录 | |
| base_dir = "/home/yz979/palmer_scratch/chengye/1000_arxiv/pdf2figure/data" | |
| json_files = [] | |
| file_names = [] | |
| # 遍历目录 | |
| for root, dirs, files in os.walk(base_dir): | |
| for file in files: | |
| if file.endswith(".json"): | |
| full_path = os.path.join(root, file) | |
| json_files.append(full_path) | |
| file_names.append(file) | |
| for i in tqdm(range(0,len(json_files))): | |
| table = {} | |
| with open(json_files[i],'r',encoding='utf-8')as f: | |
| data = json.load(f) | |
| for item in data: | |
| if item['figType'] == 'Table': | |
| item['renderURL'] = item['renderURL'].split('/')[-1] | |
| item.pop("imageText", None) | |
| table[item['name']] = item | |
| paper_path = '/home/yz979/palmer_scratch/chengye/1000_arxiv/papers/'+file_names[i] | |
| with open(paper_path,'r',encoding='utf-8')as f: | |
| data = json.load(f) | |
| data['new_table'] = table | |
| with open(paper_path, "w", encoding="utf-8") as f: | |
| json.dump(data, f, ensure_ascii=False, indent=2) | |