Spaces:
Running
Running
File size: 1,207 Bytes
d2b9031 49e25d2 ff86828 d2b9031 fcd8f70 49e25d2 fcd8f70 a92db70 fcd8f70 ff86828 7773ef1 49e25d2 fcd8f70 49e25d2 72dd3ca ff86828 |
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 requests
from io import BytesIO
def convert_csv_to_parquet(csv_file=None, csv_url=None):
# Read the CSV file either from an uploaded file or from a URL
if csv_file is not None:
df = pd.read_csv(csv_file.name)
elif csv_url is not None:
response = requests.get(csv_url)
response.raise_for_status() # Ensure the request was successful
df = pd.read_csv(BytesIO(response.content))
else:
raise ValueError("Either csv_file or csv_url must be provided")
# Optionally, perform any cleaning on the DataFrame here if needed
# Save the DataFrame as a Parquet file
output_file_path = "output.parquet"
df.to_parquet(output_file_path, index=False)
return output_file_path
demo = gr.Interface(
fn=convert_csv_to_parquet,
inputs=[
gr.File(label="CSV File"),
gr.Textbox(label="CSV File URL", placeholder="Enter a URL to a CSV file")
],
outputs=[gr.File(label="Parquet Output")],
title="CSV to Parquet Converter",
description="Convert a CSV file to Parquet format from a downloadable link or file upload"
)
if __name__ == "__main__":
demo.launch()
|