<commit_before>from __future__ import print_function
import os
import datetime
import time
import requests
import grpc
import platoai
from tqdm import tqdm

# TODO: improve testing...


def test_local(metadata, file_name='test.wav', channel=None):
    with open(file_name, 'rb') as f:
        with tqdm(total=os.path.getsize(file_name)) as pbar:
            try:
                pbar.write(
                    str(platoai.push(
                        audio=f,
                        metadata=metadata,
                        callbacks=[pbar.update],
                        channel=channel)))
            except grpc.RpcError as e:
                pbar.write(e)


def test_remote_simple(metadata,
                       url='https://students.cs.byu.edu/~wmyers7/test.wav',
                       channel=None):
    download_request = requests.get(url, stream=True)
    r = requests.head(url)  # TODO: shouldnt need a separate head request
    with tqdm(total=int(r.headers['content-length'])) as pbar:
        try:
            pbar.write(
                str(platoai.push(
                    audio=download_request.raw,
                    metadata=metadata,
                    callbacks=[pbar.update],
                    channel=channel)))
        except grpc.RpcError as e:
            pbar.write(e)


def test_remote_complex(metadata,
                        url='https://students.cs.byu.edu/~wmyers7/test.wav',
                        chunk_size=1024,
                        channel=None):
    download_request = requests.get(url, stream=True)
    r = requests.head(url)  # TODO: shouldnt need a separate head request
    with tqdm(total=int(r.headers['content-length'])) as pbar:
        with platoai.PushRequest(
                metadata,
                channel=channel,
                chunk_size=chunk_size,
                callbacks=[pbar.update]) as push_request:
            for chunk in download_request.iter_content(chunk_size=chunk_size):
                if chunk:
                    push_request.write(chunk)
            try:
                pbar.write(str(push_request.push()))
            except grpc.RpcError as e:
                pbar.write(e)


if __name__ == '__main__':<commit_msg>Reformat code<commit_after>from __future__ import print_function
import os
import datetime
import time
import requests
import grpc
import platoai
from tqdm import tqdm

# TODO: improve testing...


def test_local(metadata, file_name='test.wav', channel=None):
    with open(file_name, 'rb') as f:
        with tqdm(total=os.path.getsize(file_name)) as pbar:
            try:
                pbar.write(
                    str(
                        platoai.push(
                            audio=f,
                            metadata=metadata,
                            callbacks=[pbar.update],
                            channel=channel)))
            except grpc.RpcError as e:
                pbar.write(e)


def test_remote_simple(metadata,
                       url='https://students.cs.byu.edu/~wmyers7/test.wav',
                       channel=None):
    download_request = requests.get(url, stream=True)
    r = requests.head(url)  # TODO: shouldnt need a separate head request
    with tqdm(total=int(r.headers['content-length'])) as pbar:
        try:
            pbar.write(
                str(
                    platoai.push(
                        audio=download_request.raw,
                        metadata=metadata,
                        callbacks=[pbar.update],
                        channel=channel)))
        except grpc.RpcError as e:
            pbar.write(e)


def test_remote_complex(metadata,
                        url='https://students.cs.byu.edu/~wmyers7/test.wav',
                        chunk_size=1024,
                        channel=None):
    download_request = requests.get(url, stream=True)
    r = requests.head(url)  # TODO: shouldnt need a separate head request
    with tqdm(total=int(r.headers['content-length'])) as pbar:
        with platoai.PushRequest(
                metadata,
                channel=channel,
                chunk_size=chunk_size,
                callbacks=[pbar.update]) as push_request:
            for chunk in download_request.iter_content(chunk_size=chunk_size):
                if chunk:
                    push_request.write(chunk)
            try:
                pbar.write(str(push_request.push()))
            except grpc.RpcError as e:
                pbar.write(e)


if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.09325044404973357, 'fraction_numerical': 0.0026642984014209592, 'mean_word_length': 1.5861079219288174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4677030', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1222, 'n_words': 254}