Added Comments

This commit is contained in:
Artur Hyrenko 2026-02-04 20:44:53 +00:00
parent 5f05bc2460
commit c77bbb9d2a

View File

@ -4,17 +4,33 @@
import os
import shutil
# === CONFIG ===
OUTPUTS_DIR = "/home/hyrenko/Diploma/outputs" # откуда брать
DEST_DIR = "/home/hyrenko/Diploma/response" # базовая папка назначения
# =========================
# 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 INTERACTIVELY ===
# -----------------------------------------------------------------------------
# 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")
@ -31,16 +47,33 @@ def pick_model():
else:
print("Invalid selection, try again.")
# === MAIN ===
# -----------------------------------------------------------------------------
# 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}")
# Папка назначения — /response/<model_name>/
# Destination folder: /response/<model_name>/
dest_path = os.path.join(DEST_DIR, model_name)
os.makedirs(dest_path, exist_ok=True)
# Сканируем все подпапки в outputs
# 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))])
@ -48,7 +81,7 @@ def main():
copied = 0
for subdir in subdirs:
# фильтруем только те, где в названии есть имя модели
# Filter only subfolders whose name includes the selected model name
if model_name not in subdir:
continue
@ -70,5 +103,6 @@ def main():
if copied == 0:
print("[WARN] No matching response.json files were found.")
if __name__ == "__main__":
main()