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()