Download data/code.py from Eren5717/DPL_issues: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/datasets/Eren5717/DPL_issues/resolve/main/data/code.py
- Command line
-
hf download hf://datasets/Eren5717/DPL_issues/data/code.py
-
curl -L -o code.py https://huggingface.co/datasets/Eren5717/DPL_issues/resolve/main/data/code.py
1.36 kB
| import json | |
| # Specify the path to your JSON file | |
| file_path = 'github_dataset.json' | |
| def update_custom_key_in_json(file_path): | |
| try: | |
| # Open the JSON file and load the data | |
| with open(file_path, 'r') as file: | |
| data = json.load(file) | |
| # Check if the data is a list of dictionaries | |
| if isinstance(data, list): | |
| for item in data: | |
| if isinstance(item, dict) and 'output' in item: | |
| # Get the 'output' value and split it into words | |
| output_text = item['output'] | |
| item['instruction'] = 'you are the github assistant' | |
| words = output_text.split() | |
| # Truncate the words to 2048 words if needed | |
| if len(words) > 2048: | |
| item['output'] = ' '.join(words[:2048]) | |
| # Save the updated data back to the JSON file | |
| with open(file_path, 'w') as file: | |
| json.dump(data, file, indent=4) | |
| print("Output truncated to 2048 words successfully!") | |
| else: | |
| print("The JSON file doesn't contain a list of dictionaries.") | |
| except Exception as e: | |
| print(f"An error occurred: {e}") | |
| # Call the function to update the custom key | |
| update_custom_key_in_json(file_path) | |