Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,27 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
import pandas as pd
|
| 3 |
import gradio as gr
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
@spaces.GPU
|
| 7 |
-
def download_file(url):
|
| 8 |
-
response = requests.get(url)
|
| 9 |
-
return response.content
|
| 10 |
|
| 11 |
-
def convert_parquet_to_jsonl(parquet_file):
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
jsonl_data = df.to_json(orient='records', lines=True)
|
| 14 |
-
return jsonl_data
|
| 15 |
-
|
| 16 |
-
def main(url):
|
| 17 |
-
parquet_file = download_file(url)
|
| 18 |
-
jsonl_data = convert_parquet_to_jsonl(parquet_file)
|
| 19 |
with open("output.jsonl", "w") as f:
|
| 20 |
f.write(jsonl_data)
|
| 21 |
return "output.jsonl"
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
)
|
| 31 |
-
demo.launch()
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def convert_parquet_to_jsonl(parquet_file=None, parquet_url=None):
|
| 6 |
+
if parquet_file is not None:
|
| 7 |
+
df = pd.read_parquet(parquet_file.name)
|
| 8 |
+
elif parquet_url is not None:
|
| 9 |
+
response = requests.get(parquet_url)
|
| 10 |
+
df = pd.read_parquet(response.content)
|
| 11 |
+
else:
|
| 12 |
+
raise ValueError("Either parquet_file or parquet_url must be provided")
|
| 13 |
jsonl_data = df.to_json(orient='records', lines=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
with open("output.jsonl", "w") as f:
|
| 15 |
f.write(jsonl_data)
|
| 16 |
return "output.jsonl"
|
| 17 |
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=convert_parquet_to_jsonl,
|
| 20 |
+
inputs=[gr.File(label="Parquet File"), gr.Textbox(label="Parquet File URL")],
|
| 21 |
+
outputs=[gr.File(label="JSONL Output")],
|
| 22 |
+
title="Parquet to JSONL Converter",
|
| 23 |
+
description="Convert a Parquet file to JSONL format from a downloadable link or file upload"
|
| 24 |
+
)
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
| 27 |
+
demo.launch()
|