<commit_before>import os
import jinja2
import json

def render(spec, width=None, height=None):
	
	from jinja2 import Template, escape

	if width is None:
		width = 500;
	if height is None:
		height = 300

	location = os.path.join(os.path.dirname(__file__), 'templates/template.html')
	base = open(location).read()
	d = spec.to_dict()
	d['config'] = {'width': width, 'height': height}
	spec = escape(json.dumps(d))
	fields = {'spec': spec, 'width': width, 'height': height}
	t = Template(base)
	html = t.render(**fields)
	return html<commit_msg>Handle scalar conversions<commit_after>import os
import jinja2
import json
import numpy

def render(spec, width=None, height=None):
	
	from jinja2 import Template, escape

	if width is None:
		width = 500;
	if height is None:
		height = 300

	location = os.path.join(os.path.dirname(__file__), 'templates/template.html')
	base = open(location).read()
	d = spec.to_dict()
	d['config'] = {'width': width, 'height': height}

	class NumpyConvert(json.JSONEncoder):
		def default(self, obj):
			if isinstance(obj, numpy.generic):
				return numpy.asscalar(obj)
			return json.JSONEncoder.default(self, obj)

	spec = escape(json.dumps(d, cls=NumpyConvert))
	fields = {'spec': spec, 'width': width, 'height': height}
	t = Template(base)
	html = t.render(**fields)
	return html
{'fraction_non_alphanumeric': 0.14394516374714394, 'fraction_numerical': 0.012185833968012186, 'mean_word_length': 4.788546255506608, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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}}
{'dir': 'git-commits-cleaned', 'id': '4773130', 'n_tokens_mistral': 480, 'n_tokens_neox': 439, 'n_words': 125}