png_to_bin / app.py
chohj06ms's picture
Update app.py
63e04ad verified
raw
history blame contribute delete
414 Bytes
import gradio as gr
from PIL import Image
binary_file_path = 'data.bin'
def i2b(a):
image = Image.fromarray(a, 'RGB')
binary_data = image.tobytes()
with open(binary_file_path, 'wb') as f:
f.write(binary_data)
return "", "data.bin"
with gr.Blocks() as demo:
with gr.Row():
img = gr.Image(type="pil")
out = gr.File()
img.upload(i2b, img, [img, out])
demo.launch()