prithivMLmods commited on
Commit
d518747
·
verified ·
1 Parent(s): cb6a037

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import pyarrow as pa
4
+ import pyarrow.parquet as pq
5
+ from PIL import Image
6
+ import io
7
+ import base64
8
+
9
+ def image_to_parquet(images):
10
+ # List to store image data
11
+ image_data = []
12
+
13
+ for image in images:
14
+ # Convert image to bytes
15
+ buffered = io.BytesIO()
16
+ image.save(buffered, format="PNG")
17
+ img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
18
+
19
+ # Store image data and name
20
+ image_data.append({"name": image.name, "data": img_str})
21
+
22
+ # Create DataFrame
23
+ df = pd.DataFrame(image_data)
24
+
25
+ # Convert DataFrame to PyArrow Table
26
+ table = pa.Table.from_pandas(df)
27
+
28
+ # Save table as Parquet file
29
+ parquet_buffer = io.BytesIO()
30
+ pq.write_table(table, parquet_buffer)
31
+
32
+ # Return Parquet file
33
+ parquet_buffer.seek(0)
34
+ return parquet_buffer
35
+
36
+ def download_parquet(file):
37
+ return file
38
+
39
+ # Gradio interface
40
+ with gr.Blocks() as demo:
41
+ with gr.Row():
42
+ image_input = gr.File(label="Upload Images", type="file", file_count="multiple", file_types=["image"])
43
+ download_button = gr.File(label="Download Parquet File")
44
+
45
+ convert_button = gr.Button("Convert to Parquet")
46
+
47
+ convert_button.click(fn=image_to_parquet, inputs=[image_input], outputs=[download_button])
48
+
49
+ demo.launch()