Spaces:
Sleeping
Sleeping
prithivMLmods
commited on
Commit
•
b53bd23
1
Parent(s):
d518747
Update app.py
Browse files
app.py
CHANGED
@@ -6,18 +6,20 @@ from PIL import Image
|
|
6 |
import io
|
7 |
import base64
|
8 |
|
9 |
-
def image_to_parquet(
|
10 |
# List to store image data
|
11 |
image_data = []
|
12 |
|
13 |
-
for
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
|
19 |
# Store image data and name
|
20 |
-
image_data.append({"name":
|
21 |
|
22 |
# Create DataFrame
|
23 |
df = pd.DataFrame(image_data)
|
@@ -39,8 +41,8 @@ def download_parquet(file):
|
|
39 |
# Gradio interface
|
40 |
with gr.Blocks() as demo:
|
41 |
with gr.Row():
|
42 |
-
image_input = gr.File(label="Upload Images", type="
|
43 |
-
download_button = gr.File(label="Download Parquet File")
|
44 |
|
45 |
convert_button = gr.Button("Convert to Parquet")
|
46 |
|
|
|
6 |
import io
|
7 |
import base64
|
8 |
|
9 |
+
def image_to_parquet(files):
|
10 |
# List to store image data
|
11 |
image_data = []
|
12 |
|
13 |
+
for file_info in files:
|
14 |
+
# Read image
|
15 |
+
with open(file_info.name, "rb") as image_file:
|
16 |
+
img = Image.open(image_file)
|
17 |
+
buffered = io.BytesIO()
|
18 |
+
img.save(buffered, format="PNG")
|
19 |
+
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
20 |
|
21 |
# Store image data and name
|
22 |
+
image_data.append({"name": file_info.orig_name, "data": img_str})
|
23 |
|
24 |
# Create DataFrame
|
25 |
df = pd.DataFrame(image_data)
|
|
|
41 |
# Gradio interface
|
42 |
with gr.Blocks() as demo:
|
43 |
with gr.Row():
|
44 |
+
image_input = gr.File(label="Upload Images", type="filepath", file_count="multiple", file_types=["image"])
|
45 |
+
download_button = gr.File(label="Download Parquet File", interactive=False)
|
46 |
|
47 |
convert_button = gr.Button("Convert to Parquet")
|
48 |
|