import gradio as gr import cv2 from PIL import Image import base64 from io import BytesIO def run(image): if image is None: raise gr.Error('No input image') buffer = BytesIO() input_image.save(buffer, format='PNG') img_str = base64.b64encode(buffer.getvalue()).decode("utf-8") return img_str with gr.Blocks() as demo: with gr.Row(): with gr.Column(): image = gr.Image(type='pil', interactive=True) submit = gr.Button() output_text = gr.Textbox(interactive=False) submit.click( fn=run, inputs=[image], outputs=[output_text], ) demo.launch(show_error=True)