<jupyter_start><jupyter_text>BIDS v1.1.1 Notebook  1. Describe your dataset in a json file<jupyter_code>import json
import os
import pandas as pd
import numpy as np
import ipywidgets as widgets # load library for interactive widgets (drop-down lists, button, etc.)
from ipywidgets import HBox, Label, Layout
from IPython.core.display import display, HTML
from IPython.display import clear_output

### Define some useful functions

# Button
def mybutton(mydescription):
    mybuttonis = widgets.Button(
    description = mydescription,
    disabled = False,
    button_style = '', # 'success', 'info', 'warning', 'danger' or ''    
    )
    return mybuttonis

# Textbox
def mytextbox(placeholder):
    mytextboxis = widgets.Text(
        #value='Type dataset name',
        placeholder=placeholder,
        disabled=False,
        layout=Layout(width='60%')
    )
    return mytextboxis

### Excel template
templates_folder = 'https://github.com/bvhpatel/DOPE/raw/master/templates' #location of the form templates
file_name = 'dataset_description.xlsx'
file_path = os.path.join(templates_folder, file_name)
file_dwld = ' Dowload file <a href= {0}>dataset_description.xlsx</a>, fill it out, and save it in your dataset'.format(file_path)
display(HTML(file_dwld))

print()
print()
### File location
xlfilepath_textbox = mytextbox(r'e.g. C:\User\Desktop\DOPEv1.1\examples\BIDS')
datafilename_box = HBox([Label('Indicate path of dataset_description.xlsx folder:'), xlfilepath_textbox])
display(datafilename_box)

### Button create json file
createjson_button = mybutton('Create json')
json_box = HBox([Label('Click here to generate json file:'), createjson_button])
display(json_box)

output = widgets.Output()
@output.capture()
def createjson_button_clicked(b):
    clear_output()
    print("Creating json file")
    mypath = xlfilepath_textbox.value
    jsonfilename = 'dataset_description'
    excelpath =  mypath + '\\' + jsonfilename + '.xlsx'
    df = pd.read_excel(excelpath)
    df.fillna('', inplace=True)
    mydata = {}
    count = -1
    filePathNameWExt2 =  mypath + '\\' + jsonfilename + '.json'
    for item in df['Field']:
        count += 1
        mydata[item] = df['Entry'].iloc[count]  
    def writeToJSONFile(path, fileName, data):
        filePathNameWExt =  path + '\\' + fileName + '.json'
        with open(filePathNameWExt, 'w') as fp:
            json.dump(data, fp)
    writeToJSONFile(mypath,jsonfilename,mydata)
    print("json file is created at", filePathNameWExt2 )
createjson_button.on_click(createjson_button_clicked)
display(output)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11676300578034682, 'fraction_numerical': 0.005009633911368015, 'mean_word_length': 4.276422764227642, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '580998', 'license': 'MIT', 'n_tokens_mistral': 847, 'n_tokens_neox': 835, 'n_words': 205, 'path': 'notebooks/BIDS_MRI_notebook.ipynb', 'repo_name': 'bvhpatel/DOPE', 'size': '2595'}