prithivMLmods commited on
Commit
b0c7311
·
verified ·
1 Parent(s): 735e3fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -7,42 +7,46 @@ import io
7
  import base64
8
  import tempfile
9
 
 
 
 
 
 
 
 
 
 
 
10
  def image_to_parquet(files):
11
- # List to store image data
12
  image_data = []
13
 
14
  for file_info in files:
15
- # Read image
16
  with open(file_info, "rb") as image_file:
17
  img = Image.open(image_file)
18
  buffered = io.BytesIO()
19
  img.save(buffered, format="PNG")
20
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
21
 
22
- # Store image data and name
23
  image_data.append({"name": file_info, "data": img_str})
24
 
25
- # Create DataFrame
26
  df = pd.DataFrame(image_data)
27
 
28
- # Convert DataFrame to PyArrow Table
29
  table = pa.Table.from_pandas(df)
30
-
31
- # Save table as Parquet file
32
  with tempfile.NamedTemporaryFile(delete=False, suffix=".parquet") as tmp_file:
33
  pq.write_table(table, tmp_file)
34
  parquet_file_path = tmp_file.name
35
 
36
- # Return Parquet file path
37
  return parquet_file_path
38
 
39
- # Gradio interface
40
- with gr.Blocks() as demo:
41
  with gr.Row():
42
  image_input = gr.File(label="Upload Images", type="filepath", file_count="multiple", file_types=["image"])
43
  download_button = gr.File(label="Download Parquet File", interactive=False)
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
 
 
7
  import base64
8
  import tempfile
9
 
10
+
11
+ css = '''
12
+ .gradio-container{max-width: 600px !important}
13
+ h1{text-align:center}
14
+ '''
15
+
16
+ DESCRIPTIONz= """## Image to Parquet 📂
17
+
18
+ """
19
+
20
  def image_to_parquet(files):
21
+
22
  image_data = []
23
 
24
  for file_info in files:
 
25
  with open(file_info, "rb") as image_file:
26
  img = Image.open(image_file)
27
  buffered = io.BytesIO()
28
  img.save(buffered, format="PNG")
29
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
30
 
 
31
  image_data.append({"name": file_info, "data": img_str})
32
 
 
33
  df = pd.DataFrame(image_data)
34
 
 
35
  table = pa.Table.from_pandas(df)
36
+
 
37
  with tempfile.NamedTemporaryFile(delete=False, suffix=".parquet") as tmp_file:
38
  pq.write_table(table, tmp_file)
39
  parquet_file_path = tmp_file.name
40
 
 
41
  return parquet_file_path
42
 
43
+ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
44
+ gr.Markdown(DESCRIPTIONz)
45
  with gr.Row():
46
  image_input = gr.File(label="Upload Images", type="filepath", file_count="multiple", file_types=["image"])
47
  download_button = gr.File(label="Download Parquet File", interactive=False)
48
 
49
+ convert_button = gr.Button("Convert Image to Parquet")
50
 
51
  convert_button.click(fn=image_to_parquet, inputs=[image_input], outputs=[download_button])
52