Spaces:
Sleeping
Sleeping
import gradio as gr | |
import base64 | |
from PIL import Image | |
import io | |
def image_to_base64(image): | |
# Convert PIL Image to bytes | |
buffered = io.BytesIO() | |
image.save(buffered, format="JPEG") | |
# Encode bytes to Base64 string | |
img_str = base64.b64encode(buffered.getvalue()).decode() | |
return img_str | |
# Define the Gradio interface using the updated syntax | |
iface = gr.Interface( | |
fn=image_to_base64, | |
inputs=gr.Image(type="pil"), | |
outputs=gr.Textbox(), | |
title="Image to Base64 Encoder", | |
description="Upload an image and convert it to a Base64 encoded string." | |
) | |
# Launch the interface | |
iface.launch() | |