|
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): |
|
|
|
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() |
|
df = pd.read_csv(BytesIO(response.content)) |
|
else: |
|
raise ValueError("Either csv_file or csv_url must be provided") |
|
|
|
|
|
|
|
|
|
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() |
|
|