File size: 630 Bytes
1576a7f
 
 
 
 
 
 
 
 
 
 
 
 
db62c2e
1576a7f
 
db62c2e
 
1576a7f
 
 
 
 
db62c2e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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()