Spaces:
Sleeping
Sleeping
user-agent
commited on
Commit
•
1576a7f
1
Parent(s):
ff47322
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import base64
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
+
|
6 |
+
def image_to_base64(image):
|
7 |
+
# Convert PIL Image to bytes
|
8 |
+
buffered = io.BytesIO()
|
9 |
+
image.save(buffered, format="JPEG")
|
10 |
+
# Encode bytes to Base64 string
|
11 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
12 |
+
return img_str
|
13 |
+
|
14 |
+
# Define the Gradio interface
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=image_to_base64,
|
17 |
+
inputs=gr.inputs.Image(type="pil"),
|
18 |
+
outputs="text",
|
19 |
+
title="Image to Base64 Encoder",
|
20 |
+
description="Upload an image and convert it to a Base64 encoded string."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Launch the interface
|
24 |
+
iface.launch()
|