mrcuddle commited on
Commit
d2b9031
·
verified ·
1 Parent(s): 7773ef1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -1,17 +1,15 @@
1
- import gradio as gr
2
- import pandas as pd
3
  import requests
 
 
4
  import spaces
5
 
6
  @spaces.GPU
7
- def convert_parquet_to_jsonl(parquet_file=None, parquet_url=None):
8
- if parquet_file is not None:
9
- df = pd.read_parquet(parquet_file.name)
10
- elif parquet_url is not None:
11
- response = requests.get(parquet_url)
12
- df = pd.read_parquet(response.content)
13
- else:
14
- raise ValueError("Either parquet_file or parquet_url must be provided")
15
  jsonl_data = df.to_json(orient='records', lines=True)
16
  return jsonl_data
17
 
@@ -22,15 +20,15 @@ def main(url):
22
  f.write(jsonl_data)
23
  return "output.jsonl"
24
 
25
- theme = "Ytheme/Minecraft"
26
-
27
- demo = gr.Interface(theme=theme,
28
- fn=convert_parquet_to_jsonl,
29
- inputs=[gr.File(label="Parquet File"), gr.Textbox(label="Parquet File URL")],
30
- outputs=[gr.File(label="JSONL Output")],
31
- title="Parquet to JSONL Converter",
32
- description="Input a Parquet file by a downloadable link or file upload and convert it to JSONL format"
33
- )
34
 
35
  if __name__ == "__main__":
36
- demo.launch()
 
 
 
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
 
 
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()