parquet-2-JSONL / app.py
mrcuddle's picture
Update app.py
3d7aa14 verified
raw
history blame contribute delete
966 Bytes
import gradio as gr
import pandas as pd
import requests
import spaces
@spaces.GPU
def convert_parquet_to_jsonl(parquet_file=None, parquet_url=None):
if parquet_file is not None:
df = pd.read_parquet(parquet_file.name)
elif parquet_url is not None:
response = requests.get(parquet_url)
df = pd.read_parquet(response.content)
else:
raise ValueError("Either parquet_file or parquet_url must be provided")
jsonl_data = df.to_json(orient='records', lines=True)
with open("output.jsonl", "w") as f:
f.write(jsonl_data)
return "output.jsonl"
demo = gr.Interface(
fn=convert_parquet_to_jsonl,
inputs=[gr.File(label="Parquet File"), gr.Textbox(label="Parquet File URL")],
outputs=[gr.File(label="JSONL Output")],
title="Parquet to JSONL Converter",
description="Convert a Parquet file to JSONL format from a downloadable link or file upload"
)
if __name__ == "__main__":
demo.launch()