Upload src/batch_create_tiles.py with huggingface_hub
Browse files- src/batch_create_tiles.py +73 -0
src/batch_create_tiles.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import os
|
| 3 |
+
import argparse
|
| 4 |
+
|
| 5 |
+
# リファクタリングされたタイル生成関数をインポート
|
| 6 |
+
from create_tile_from_topic import create_knowledge_tile_pipeline
|
| 7 |
+
|
| 8 |
+
async def batch_create_tiles(topics_file: str, output_dir: str, domain: str):
|
| 9 |
+
"""
|
| 10 |
+
トピックリストを読み込み、指定されたドメインの知識タイルをバッチ処理で生成します。
|
| 11 |
+
"""
|
| 12 |
+
print(f"--- バッチ処理開始 ---")
|
| 13 |
+
print(f" トピックファイル: {topics_file}")
|
| 14 |
+
print(f" 出力ディレクトリ: {output_dir}")
|
| 15 |
+
print(f" 対象ドメイン: {domain}")
|
| 16 |
+
|
| 17 |
+
# 出力先ディレクトリがなければ作成
|
| 18 |
+
if not os.path.exists(output_dir):
|
| 19 |
+
os.makedirs(output_dir)
|
| 20 |
+
print(f"出力先ディレクトリを作成しました: {output_dir}")
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
with open(topics_file, 'r', encoding='utf-8') as f:
|
| 24 |
+
topics = [line.strip() for line in f if line.strip()]
|
| 25 |
+
except FileNotFoundError:
|
| 26 |
+
print(f"エラー: トピックファイル '{topics_file}' が見つかりません。")
|
| 27 |
+
return
|
| 28 |
+
|
| 29 |
+
print(f"{len(topics)}件のトピックを処理します。")
|
| 30 |
+
|
| 31 |
+
created_files = []
|
| 32 |
+
for i, topic in enumerate(topics):
|
| 33 |
+
print(f"\n({i+1}/{len(topics)}) 処理中: {topic}")
|
| 34 |
+
|
| 35 |
+
safe_filename = topic.replace(" ", "_").replace("/", "_").replace("(", "").replace(")", "")[:30]
|
| 36 |
+
output_path = os.path.join(output_dir, f"{safe_filename}.iath")
|
| 37 |
+
|
| 38 |
+
generated_file = await create_knowledge_tile_pipeline(
|
| 39 |
+
topic=topic,
|
| 40 |
+
domain_id=domain, # ドメインを指定
|
| 41 |
+
output_filename=output_path,
|
| 42 |
+
save_json=False
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
if generated_file:
|
| 46 |
+
created_files.append(generated_file)
|
| 47 |
+
|
| 48 |
+
print("\n--- バッチ処理完了 ---")
|
| 49 |
+
print(f"{len(created_files)}件の.iathファイルを {output_dir} に生成しました。")
|
| 50 |
+
|
| 51 |
+
def main():
|
| 52 |
+
parser = argparse.ArgumentParser(description="Ilm-Athens 知識タイルバッチ生成ツール")
|
| 53 |
+
parser.add_argument(
|
| 54 |
+
"--topics-file",
|
| 55 |
+
default="topics.txt",
|
| 56 |
+
help="トピックをリストしたテキストファイル (デフォルト: topics.txt)"
|
| 57 |
+
)
|
| 58 |
+
parser.add_argument(
|
| 59 |
+
"--output-dir",
|
| 60 |
+
default="generated_tiles",
|
| 61 |
+
help="生成された.iathファイルを保存するディレクトリ (デフォルト: generated_tiles)"
|
| 62 |
+
)
|
| 63 |
+
parser.add_argument(
|
| 64 |
+
"--domain",
|
| 65 |
+
default="medical",
|
| 66 |
+
help="対象とする知識ドメイン (例: medical, legal) (デフォルト: medical)"
|
| 67 |
+
)
|
| 68 |
+
args = parser.parse_args()
|
| 69 |
+
|
| 70 |
+
asyncio.run(batch_create_tiles(args.topics_file, args.output_dir, args.domain))
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
main()
|