<commit_before>
import base64
import json
import numpy
import urllib.request
import uuid

from . import png

__all__ = ['URL', 'image', 'images', 'plot']

URL = 'http://localhost:8000/events'


def uid():
  return 'pane_%s' % uuid.uuid4()


def send(**command):
  command = json.dumps(command)
  req = urllib.request.Request(URL, method='POST')
  req.add_header('Content-Type', 'application/json')
  req.data = command.encode('ascii')
  try:
    resp = urllib.request.urlopen(req)
    return resp != None
  except:
    raise
    return False


def normalize(img, opts):
  minval = opts.get('min')
  if minval is None:
    minval = numpy.amin(img)
  maxval = opts.get('max')
  if maxval is None:
    maxval = numpy.amax(img)

  return numpy.uint8((img - minval) * (255/(maxval - minval)))
<commit_msg>Keep python wrapper from crashing display server<commit_after>
import base64
import json
import numpy
import urllib.request
import uuid

from . import png

__all__ = ['URL', 'image', 'images', 'plot']

URL = 'http://localhost:8000/events'


def uid():
  return 'pane_%s' % uuid.uuid4()


def send(**command):
  command = json.dumps(command)
  req = urllib.request.Request(URL, method='POST')
  req.add_header('Content-Type', 'application/text')
  req.data = command.encode('ascii')
  try:
    resp = urllib.request.urlopen(req)
    return resp != None
  except:
    raise
    return False


def normalize(img, opts):
  minval = opts.get('min')
  if minval is None:
    minval = numpy.amin(img)
  maxval = opts.get('max')
  if maxval is None:
    maxval = numpy.amax(img)

  return numpy.uint8((img - minval) * (255/(maxval - minval)))

{'fraction_non_alphanumeric': 0.14678899082568808, 'fraction_numerical': 0.01345565749235474, 'mean_word_length': 3.7420289855072464, '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': '2836661', 'n_tokens_mistral': 598, 'n_tokens_neox': 572, 'n_words': 148}