Spaces:
Sleeping
Sleeping
File size: 1,128 Bytes
b91b28a 9a4f8ab b91b28a 3650b3d b91b28a |
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 |
import gradio as gr
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
import tempfile
css = '''
.gradio-container{max-width: 950px !important}
h1{text-align:center}
'''
DESCRIPTIONz= """## CSV to Parquet π
"""
def csv_to_parquet(file):
df = pd.read_csv(file.name)
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():
csv_input = gr.File(label="Upload CSV File", type="filepath", file_types=["text/csv"])
download_button = gr.File(label="Download Parquet File", interactive=False)
convert_button = gr.Button("Convert CSV to Parquet")
convert_button.click(fn=csv_to_parquet, inputs=[csv_input], outputs=[download_button])
gr.Markdown("π The speed of converting a CSV file to a .parquet file depends on the size and complexity of the CSV file.")
demo.launch() |