File size: 1,658 Bytes
d518747
 
 
 
 
 
 
735e3fc
d518747
b0c7311
 
6e8d8db
b0c7311
 
 
 
 
 
 
b53bd23
b0c7311
d518747
 
b53bd23
80f86f6
b53bd23
 
 
 
d518747
80f86f6
d518747
 
 
 
b0c7311
735e3fc
 
 
d518747
735e3fc
d518747
6b5f8e9
b0c7311
d518747
b53bd23
 
d518747
b0c7311
d518747
 
 
f1540c8
735e3fc
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import gradio as gr
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
from PIL import Image
import io
import base64
import tempfile


css = '''
.gradio-container{max-width: 950px !important}
h1{text-align:center}
'''

DESCRIPTIONz= """## Image to Parquet πŸ“‚

"""

def image_to_parquet(files):

    image_data = []

    for file_info in files:
        with open(file_info, "rb") as image_file:
            img = Image.open(image_file)
            buffered = io.BytesIO()
            img.save(buffered, format="PNG")
            img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
        
        image_data.append({"name": file_info, "data": img_str})
    
    df = pd.DataFrame(image_data)
    
    table = pa.Table.from_pandas(df)

    with tempfile.NamedTemporaryFile(delete=False, suffix=".parquet") as tmp_file:
        pq.write_table(table, tmp_file)
        parquet_file_path = tmp_file.name
    
    return parquet_file_path

with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
    gr.Markdown(DESCRIPTIONz)
    with gr.Row():
        image_input = gr.File(label="Upload Images", type="filepath", file_count="multiple", file_types=["image"])
        download_button = gr.File(label="Download Parquet File", interactive=False)
        
    convert_button = gr.Button("Convert Image to Parquet")
    
    convert_button.click(fn=image_to_parquet, inputs=[image_input], outputs=[download_button])

    gr.Markdown("πŸ“Œ speed / time of converting images to a .parquet file depends on both the number of images uploaded and the quality and size of the uploaded images invloved for the conversion.")
demo.launch()