B64ImageString / app.py
Eun02's picture
Update app.py
e258875 verified
raw
history blame
631 Bytes
import gradio as gr
import base64
from io import BytesIO
def run(image):
if image is None:
raise gr.Error('No input image')
buffer = BytesIO()
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)