Spaces:
Running
Running
import os | |
import json | |
# Define the directory path | |
directory_path = "/home/justin/LLaMA-Factory" | |
# Change directory to the specified path | |
try: | |
os.chdir(directory_path) | |
except FileNotFoundError: | |
print(f"Error: The directory {directory_path} does not exist.") | |
exit(1) | |
MODEL_NAME = "Llama-3" | |
# Define the path to the JSON file | |
json_file_path = os.path.join(directory_path, "data/identity.json") | |
# Read the JSON data from the file | |
try: | |
with open(json_file_path, "r", encoding="utf-8") as f: | |
dataset = json.load(f) | |
except FileNotFoundError: | |
print(f"Error: The file {json_file_path} does not exist.") | |
exit(1) | |
# Replace placeholders in the dataset | |
for sample in dataset: | |
sample["output"] = sample["output"].replace("MODEL_NAME", MODEL_NAME).replace("AUTHOR", "LLaMA Factory") | |
# Write the updated data back to the file | |
with open(json_file_path, "w", encoding="utf-8") as f: | |
json.dump(dataset, f, indent=2, ensure_ascii=False) | |