File size: 1,150 Bytes
72dd3ca
 
4132f1f
 
72dd3ca
4132f1f
12647e1
 
 
 
 
 
4132f1f
12647e1
72dd3ca
 
 
7773ef1
 
 
 
 
 
 
7237016
17f7cd6
 
72dd3ca
4c38f99
7773ef1
72dd3ca
4132f1f
72dd3ca
 
 
 
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
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)
    return jsonl_data

def main(url):
    parquet_file = download_file(url)
    jsonl_data = convert_parquet_to_jsonl(parquet_file)
    with open("output.jsonl", "w") as f:
        f.write(jsonl_data)
    return "output.jsonl"

theme = "Ytheme/Minecraft"

demo = gr.Interface(theme=theme,
    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="Input a Parquet file by a downloadable link or file upload and convert it to JSONL format"
)

if __name__ == "__main__":
    demo.launch()