Spaces:
Paused
Paused
Gradio 6.29; temp output dirs; theme to launch()
Browse files- README.md +1 -1
- app.py +17 -15
- requirements.txt +3 -2
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: π
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
short_description: Support by Parquet, CSV, Jsonl, XLS
|
|
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 6.29.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
short_description: Support by Parquet, CSV, Jsonl, XLS
|
app.py
CHANGED
|
@@ -4,6 +4,8 @@ import json
|
|
| 4 |
from io import BytesIO
|
| 5 |
import requests
|
| 6 |
import re
|
|
|
|
|
|
|
| 7 |
from openpyxl import Workbook
|
| 8 |
|
| 9 |
def sanitize_value(val):
|
|
@@ -45,9 +47,9 @@ def dataset_converter(input_file, conversion_type, parquet_url):
|
|
| 45 |
# Conversion: CSV to Parquet
|
| 46 |
if conversion_type == "CSV to Parquet":
|
| 47 |
if input_file is None or file_extension != "csv":
|
| 48 |
-
raise
|
| 49 |
df = pd.read_csv(BytesIO(file_bytes))
|
| 50 |
-
output_file = "output.parquet"
|
| 51 |
df.to_parquet(output_file, index=False)
|
| 52 |
converted_format = "Parquet"
|
| 53 |
preview_str = df.head(10).to_string(index=False)
|
|
@@ -55,9 +57,9 @@ def dataset_converter(input_file, conversion_type, parquet_url):
|
|
| 55 |
# Conversion: Parquet to CSV
|
| 56 |
elif conversion_type == "Parquet to CSV":
|
| 57 |
if input_file is None or file_extension != "parquet":
|
| 58 |
-
raise
|
| 59 |
df = pd.read_parquet(BytesIO(file_bytes))
|
| 60 |
-
output_file = "output.csv"
|
| 61 |
df.to_csv(output_file, index=False)
|
| 62 |
converted_format = "CSV"
|
| 63 |
preview_str = df.head(10).to_string(index=False)
|
|
@@ -65,9 +67,9 @@ def dataset_converter(input_file, conversion_type, parquet_url):
|
|
| 65 |
# Conversion: CSV to JSONL
|
| 66 |
elif conversion_type == "CSV to JSONL":
|
| 67 |
if input_file is None or file_extension != "csv":
|
| 68 |
-
raise
|
| 69 |
df = pd.read_csv(BytesIO(file_bytes), encoding='latin1')
|
| 70 |
-
output_file = "metadata.jsonl"
|
| 71 |
total_data = []
|
| 72 |
for index, row in df.iterrows():
|
| 73 |
data = {}
|
|
@@ -89,14 +91,14 @@ def dataset_converter(input_file, conversion_type, parquet_url):
|
|
| 89 |
if input_file is not None:
|
| 90 |
df = pd.read_parquet(BytesIO(file_bytes))
|
| 91 |
elif parquet_url:
|
| 92 |
-
response = requests.get(parquet_url)
|
| 93 |
response.raise_for_status()
|
| 94 |
df = pd.read_parquet(BytesIO(response.content))
|
| 95 |
file_name = "from_url.parquet"
|
| 96 |
else:
|
| 97 |
-
raise
|
| 98 |
|
| 99 |
-
output_file = "output.jsonl"
|
| 100 |
def recursive_sanitize(val):
|
| 101 |
if isinstance(val, bytes):
|
| 102 |
return val.decode("utf-8", errors="replace")
|
|
@@ -120,14 +122,14 @@ def dataset_converter(input_file, conversion_type, parquet_url):
|
|
| 120 |
if input_file is not None:
|
| 121 |
df = pd.read_parquet(BytesIO(file_bytes))
|
| 122 |
elif parquet_url:
|
| 123 |
-
response = requests.get(parquet_url)
|
| 124 |
response.raise_for_status()
|
| 125 |
df = pd.read_parquet(BytesIO(response.content))
|
| 126 |
file_name = "from_url.parquet"
|
| 127 |
else:
|
| 128 |
-
raise
|
| 129 |
|
| 130 |
-
output_file = "output.xlsx"
|
| 131 |
wb = Workbook(write_only=True)
|
| 132 |
ws = wb.create_sheet()
|
| 133 |
ws.append(list(df.columns))
|
|
@@ -139,7 +141,7 @@ def dataset_converter(input_file, conversion_type, parquet_url):
|
|
| 139 |
preview_str = df.head(10).to_string(index=False)
|
| 140 |
|
| 141 |
else:
|
| 142 |
-
raise
|
| 143 |
|
| 144 |
info_message = (
|
| 145 |
f"Input file: {file_name if file_name is not None else 'N/A'}\n"
|
|
@@ -148,7 +150,7 @@ def dataset_converter(input_file, conversion_type, parquet_url):
|
|
| 148 |
)
|
| 149 |
return output_file, info_message
|
| 150 |
|
| 151 |
-
with gr.Blocks(title="Datasets Convertor"
|
| 152 |
gr.Markdown("# Datasets Convertor π")
|
| 153 |
gr.Markdown(
|
| 154 |
"Upload a CSV or Parquet file (or provide a Parquet file URL for Parquet to JSONL/XLS conversion) "
|
|
@@ -178,4 +180,4 @@ with gr.Blocks(title="Datasets Convertor", theme="Nymbo/Nymbo_Theme") as demo:
|
|
| 178 |
outputs=[output_file, preview]
|
| 179 |
)
|
| 180 |
|
| 181 |
-
demo.launch()
|
|
|
|
| 4 |
from io import BytesIO
|
| 5 |
import requests
|
| 6 |
import re
|
| 7 |
+
import os
|
| 8 |
+
import tempfile
|
| 9 |
from openpyxl import Workbook
|
| 10 |
|
| 11 |
def sanitize_value(val):
|
|
|
|
| 47 |
# Conversion: CSV to Parquet
|
| 48 |
if conversion_type == "CSV to Parquet":
|
| 49 |
if input_file is None or file_extension != "csv":
|
| 50 |
+
raise gr.Error("For CSV to Parquet conversion, please upload a CSV file. π")
|
| 51 |
df = pd.read_csv(BytesIO(file_bytes))
|
| 52 |
+
output_file = os.path.join(tempfile.mkdtemp(), "output.parquet")
|
| 53 |
df.to_parquet(output_file, index=False)
|
| 54 |
converted_format = "Parquet"
|
| 55 |
preview_str = df.head(10).to_string(index=False)
|
|
|
|
| 57 |
# Conversion: Parquet to CSV
|
| 58 |
elif conversion_type == "Parquet to CSV":
|
| 59 |
if input_file is None or file_extension != "parquet":
|
| 60 |
+
raise gr.Error("For Parquet to CSV conversion, please upload a Parquet file. π")
|
| 61 |
df = pd.read_parquet(BytesIO(file_bytes))
|
| 62 |
+
output_file = os.path.join(tempfile.mkdtemp(), "output.csv")
|
| 63 |
df.to_csv(output_file, index=False)
|
| 64 |
converted_format = "CSV"
|
| 65 |
preview_str = df.head(10).to_string(index=False)
|
|
|
|
| 67 |
# Conversion: CSV to JSONL
|
| 68 |
elif conversion_type == "CSV to JSONL":
|
| 69 |
if input_file is None or file_extension != "csv":
|
| 70 |
+
raise gr.Error("For CSV to JSONL conversion, please upload a CSV file. π")
|
| 71 |
df = pd.read_csv(BytesIO(file_bytes), encoding='latin1')
|
| 72 |
+
output_file = os.path.join(tempfile.mkdtemp(), "metadata.jsonl")
|
| 73 |
total_data = []
|
| 74 |
for index, row in df.iterrows():
|
| 75 |
data = {}
|
|
|
|
| 91 |
if input_file is not None:
|
| 92 |
df = pd.read_parquet(BytesIO(file_bytes))
|
| 93 |
elif parquet_url:
|
| 94 |
+
response = requests.get(parquet_url, timeout=120)
|
| 95 |
response.raise_for_status()
|
| 96 |
df = pd.read_parquet(BytesIO(response.content))
|
| 97 |
file_name = "from_url.parquet"
|
| 98 |
else:
|
| 99 |
+
raise gr.Error("For Parquet to JSONL conversion, please upload a file or provide a URL. π")
|
| 100 |
|
| 101 |
+
output_file = os.path.join(tempfile.mkdtemp(), "output.jsonl")
|
| 102 |
def recursive_sanitize(val):
|
| 103 |
if isinstance(val, bytes):
|
| 104 |
return val.decode("utf-8", errors="replace")
|
|
|
|
| 122 |
if input_file is not None:
|
| 123 |
df = pd.read_parquet(BytesIO(file_bytes))
|
| 124 |
elif parquet_url:
|
| 125 |
+
response = requests.get(parquet_url, timeout=120)
|
| 126 |
response.raise_for_status()
|
| 127 |
df = pd.read_parquet(BytesIO(response.content))
|
| 128 |
file_name = "from_url.parquet"
|
| 129 |
else:
|
| 130 |
+
raise gr.Error("For Parquet to XLS conversion, please upload a file or provide a URL. π")
|
| 131 |
|
| 132 |
+
output_file = os.path.join(tempfile.mkdtemp(), "output.xlsx")
|
| 133 |
wb = Workbook(write_only=True)
|
| 134 |
ws = wb.create_sheet()
|
| 135 |
ws.append(list(df.columns))
|
|
|
|
| 141 |
preview_str = df.head(10).to_string(index=False)
|
| 142 |
|
| 143 |
else:
|
| 144 |
+
raise gr.Error("Invalid conversion type selected. β οΈ")
|
| 145 |
|
| 146 |
info_message = (
|
| 147 |
f"Input file: {file_name if file_name is not None else 'N/A'}\n"
|
|
|
|
| 150 |
)
|
| 151 |
return output_file, info_message
|
| 152 |
|
| 153 |
+
with gr.Blocks(title="Datasets Convertor") as demo:
|
| 154 |
gr.Markdown("# Datasets Convertor π")
|
| 155 |
gr.Markdown(
|
| 156 |
"Upload a CSV or Parquet file (or provide a Parquet file URL for Parquet to JSONL/XLS conversion) "
|
|
|
|
| 180 |
outputs=[output_file, preview]
|
| 181 |
)
|
| 182 |
|
| 183 |
+
demo.launch(theme="Nymbo/Nymbo_Theme")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
pandas
|
| 2 |
-
|
| 3 |
-
openpyxl
|
|
|
|
|
|
| 1 |
pandas
|
| 2 |
+
pyarrow
|
| 3 |
+
openpyxl
|
| 4 |
+
requests
|