Skip to main content

Rest api supporter

Project description

rest-api-supporter

https://pypi.org/project/rest-api-supporter/

pip install rest-api-supporter

Supported APIs

base64_encode

from PIL import Image
from rest_api_supporter.utils.base64_encode_image import base64_encode_image

image = Image.open("rock.jpg")
base64_encoded = base64_encode_image(image)
print(base64_encoded) #data:image/png;base64,/9j/4AAQSkZJRgABAQ...2qjR37P/2Q==
import datasets
from rest_api_supporter.utils.base64_encode_audio import base64_encode_audio

path = 'up.wav'
dataset = datasets.Dataset.from_dict({"audio": [path]})
dataset = dataset.cast_column("audio", datasets.Audio(sampling_rate=16_000)) #https://huggingface.co/blog/audio-datasets#1-resampling-the-audio-data
array = dataset[0]["audio"]["array"] #numpy array
#sampling_rate = dataset[0]["audio"]["sampling_rate"] #Wav2Vec2FeatureExtractor was trained using a sampling rate of 16000. Please make sure that the provided `raw_speech` input was sampled with 16000 and not 8000.
sampling_rate = 16000
base64_encoded = base64_encode_audio(array)
print(base64_encoded) #data:audio/wav;base64,UklGRiTuAgBXQVZFZm...At84WACNZGwA=
from rest_api_supporter.utils.base64_encode_video import base64_encode_video

file = "video.mp4"
with open(file, "rb") as f:
    bytes_value = f.read() #bytes
base64_encoded = base64_encode_video(bytes_value)
print(base64_encoded) #data:video/mp4;base64,/9j/4AAQSkZJRgABAQ...2qjR37P/2Q==

base64_decode

from rest_api_supporter.utils.base64_decode_image import base64_decode_image

base64_encoded = "data:image/png;base64,/9j/4AAQSkZJRgABAQ...2qjR37P/2Q=="
#base64_encoded = "/9j/4AAQSkZJRgABAQ...2qjR37P/2Q==
base64_decoded = base64_decode_image(base64_encoded)
print(type(base64_decoded)) #<class 'PIL.JpegImagePlugin.JpegImageFile'>
                            #<class 'PIL.JpegImagePlugin.JpegImageFile'>
from rest_api_supporter.utils.base64_decode_audio import base64_decode_audio

base64_encoded = "data:audio/wav;base64,UklGRiTuAgBXQVZFZm...At84WACNZGwA="
#base64_encoded = "/9j/4AAQSkZJRgABAQ...2qjR37P/2Q=="
base64_decoded = base64_decode_audio(base64_encoded)
print(type(base64_decoded)) #<class 'bytes'>
                            #<class 'bytes'>
from rest_api_supporter.utils.base64_decode_video import base64_decode_video

base64_encoded = "data:video/mp4;base64,/9j/4AAQSkZJRgABAQ...2qjR37P/2Q=="
#base64_encoded = "/9j/4AAQSkZJRgABAQ...2qjR37P/2Q=="
base64_decoded = base64_decode_video(base64_encoded)
print(type(base64_decoded)) #

======

from PIL import Image
from rest_api_supporter.utils.base64_encode import base64_encode

image = Image.open("rock.jpg")
base64_encoded = base64_encode(image)
print(base64_encoded) #data:image/png;base64,/9j/4AAQSkZJRgABAQ...2qjR37P/2Q==
import datasets
from rest_api_supporter.utils.base64_encode import base64_encode

path = 'up.wav'
dataset = datasets.Dataset.from_dict({"audio": [path]})
dataset = dataset.cast_column("audio", datasets.Audio(sampling_rate=16_000)) #https://huggingface.co/blog/audio-datasets#1-resampling-the-audio-data
array = dataset[0]["audio"]["array"] #numpy array
#sampling_rate = dataset[0]["audio"]["sampling_rate"] #Wav2Vec2FeatureExtractor was trained using a sampling rate of 16000. Please make sure that the provided `raw_speech` input was sampled with 16000 and not 8000.
sampling_rate = 16000
base64_encoded = base64_encode(array) 
print(base64_encoded) #data:audio/wav;base64,UklGRiTuAgBXQVZFZm...At84WACNZGwA=

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rest-api-supporter-0.0.27.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

rest_api_supporter-0.0.27-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file rest-api-supporter-0.0.27.tar.gz.

File metadata

  • Download URL: rest-api-supporter-0.0.27.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for rest-api-supporter-0.0.27.tar.gz
Algorithm Hash digest
SHA256 b8897cc820fbfe7441c3f32fc8e4ec44e010c0fad3900b3c81929fea6a697927
MD5 1bc34e96bdc27a8d782d7f370b4f4714
BLAKE2b-256 0b39ff6b34e57d169c89a02796eef9db643b165cb18388090dd710e0c0d21229

See more details on using hashes here.

File details

Details for the file rest_api_supporter-0.0.27-py3-none-any.whl.

File metadata

File hashes

Hashes for rest_api_supporter-0.0.27-py3-none-any.whl
Algorithm Hash digest
SHA256 9a4e4058af4970731775d00188c7e701d3d0a86962334079e453f2c9553a8956
MD5 5247f635765fba3353c72a5e85d07b6c
BLAKE2b-256 4d9aa96f61f523e6aec040c061c2f12f9e75b21e306cce0c0432f641f3aae6a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page