109 lines
3.5 KiB
Python
109 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import shutil
|
|
|
|
# =========================
|
|
# Config
|
|
# =========================
|
|
# Source directory containing run subfolders
|
|
OUTPUTS_DIR = "/home/hyrenko/Diploma/outputs"
|
|
# Destination base directory where JSON files will be copied
|
|
DEST_DIR = "/home/hyrenko/Diploma/response"
|
|
|
|
# Ensure destination folders exist
|
|
os.makedirs(DEST_DIR, exist_ok=True)
|
|
os.makedirs(os.path.join(DEST_DIR, "gemma"), exist_ok=True)
|
|
os.makedirs(os.path.join(DEST_DIR, "llama"), exist_ok=True)
|
|
os.makedirs(os.path.join(DEST_DIR, "qwen"), exist_ok=True)
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# pick_model()
|
|
# Purpose:
|
|
# Interactive menu to choose which model's outputs should be collected.
|
|
#
|
|
# Behavior:
|
|
# - Prompts user to select one of: gemma / llama / qwen
|
|
# - Keeps asking until a valid selection is entered
|
|
#
|
|
# Returns:
|
|
# A lowercase model name string: "gemma", "llama", or "qwen"
|
|
# -----------------------------------------------------------------------------
|
|
def pick_model():
|
|
print("\n=== Select model ===")
|
|
print("[1] gemma")
|
|
print("[2] llama")
|
|
print("[3] qwen")
|
|
while True:
|
|
ch = input("Choose model [1-3]: ").strip()
|
|
if ch == "1":
|
|
return "gemma"
|
|
elif ch == "2":
|
|
return "llama"
|
|
elif ch == "3":
|
|
return "qwen"
|
|
else:
|
|
print("Invalid selection, try again.")
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# main()
|
|
# Purpose:
|
|
# Copies 'responses.json' files from model-specific run folders inside OUTPUTS_DIR
|
|
# into a dedicated destination folder:
|
|
# DEST_DIR/<model_name>/
|
|
#
|
|
# Workflow:
|
|
# 1) Ask user to pick a model name.
|
|
# 2) Create destination folder DEST_DIR/<model_name>/ if needed.
|
|
# 3) Scan all subdirectories in OUTPUTS_DIR.
|
|
# 4) Keep only those whose folder name contains the selected model name.
|
|
# 5) If <subdir>/responses.json exists, copy it to:
|
|
# DEST_DIR/<model_name>/<counter>.json
|
|
# where counter starts from 1 and increments for each copied file.
|
|
# 6) Print a summary at the end.
|
|
# -----------------------------------------------------------------------------
|
|
def main():
|
|
model_name = pick_model()
|
|
print(f"\n[INFO] Selected model: {model_name}")
|
|
|
|
# Destination folder: /response/<model_name>/
|
|
dest_path = os.path.join(DEST_DIR, model_name)
|
|
os.makedirs(dest_path, exist_ok=True)
|
|
|
|
# Collect all subdirectories inside OUTPUTS_DIR
|
|
subdirs = sorted([os.path.join(OUTPUTS_DIR, d) for d in os.listdir(OUTPUTS_DIR)
|
|
if os.path.isdir(os.path.join(OUTPUTS_DIR, d))])
|
|
|
|
counter = 1
|
|
copied = 0
|
|
|
|
for subdir in subdirs:
|
|
# Filter only subfolders whose name includes the selected model name
|
|
if model_name not in subdir:
|
|
continue
|
|
|
|
src_file = os.path.join(subdir, "responses.json")
|
|
if os.path.isfile(src_file):
|
|
dst_file = os.path.join(dest_path, f"{counter}.json")
|
|
shutil.copy2(src_file, dst_file)
|
|
print(f"[{counter}] Copied from {subdir} -> {dst_file}")
|
|
counter += 1
|
|
copied += 1
|
|
else:
|
|
print(f"[SKIP] No response.json in {subdir}")
|
|
|
|
print("\n=== Summary ===")
|
|
print(f"Model: {model_name}")
|
|
print(f"Copied files: {copied}")
|
|
print(f"Destination: {dest_path}")
|
|
|
|
if copied == 0:
|
|
print("[WARN] No matching response.json files were found.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|