Spaces:
Running
Running
File size: 964 Bytes
2852136 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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)
|