CoolFace
Apppublic

user-agent/image_to_base64

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py25 linesDownload Raw Back to root
1import gradio as gr2import base643from PIL import Image4import io5 6def image_to_base64(image):7    # Convert PIL Image to bytes8    buffered = io.BytesIO()9    image.save(buffered, format="JPEG")10    # Encode bytes to Base64 string11    img_str = base64.b64encode(buffered.getvalue()).decode()12    return img_str13 14# Define the Gradio interface using the updated syntax15iface = gr.Interface(16    fn=image_to_base64, 17    inputs=gr.Image(type="pil"), 18    outputs=gr.Textbox(),19    title="Image to Base64 Encoder",20    description="Upload an image and convert it to a Base64 encoded string."21)22 23# Launch the interface24iface.launch()25