mrcuddle commited on
Commit
49e25d2
·
verified ·
1 Parent(s): d2b9031

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -25
app.py CHANGED
@@ -1,34 +1,27 @@
1
- import requests
2
- import pandas as pd
3
  import gradio as gr
4
- import spaces
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
- df = pd.read_parquet(parquet_file)
 
 
 
 
 
 
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
- def gradio_interface():
24
- demo = gr.Interface(
25
- fn=main,
26
- inputs=[gr.Textbox(label="Parquet File URL")],
27
- outputs=[gr.File(label="JSONL Output")],
28
- title="Parquet to JSONL Converter",
29
- description="Convert a Parquet file to JSONL format from a downloadable link"
30
- )
31
- demo.launch()
32
 
33
  if __name__ == "__main__":
34
- gradio_interface()
 
 
 
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()