Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,20 +14,16 @@ def convert_parquet_to_jsonl(parquet_file=None, parquet_url=None):
|
|
| 14 |
else:
|
| 15 |
raise ValueError("Either parquet_file or parquet_url must be provided")
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
return val
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
df = df.applymap(clean_string)
|
| 26 |
-
|
| 27 |
-
# Now safely convert to JSON Lines
|
| 28 |
jsonl_data = df.to_json(orient="records", lines=True)
|
| 29 |
-
|
| 30 |
-
# Write
|
| 31 |
output_file_path = "output.jsonl"
|
| 32 |
with open(output_file_path, "w", encoding="utf-8") as f:
|
| 33 |
f.write(jsonl_data)
|
|
|
|
| 14 |
else:
|
| 15 |
raise ValueError("Either parquet_file or parquet_url must be provided")
|
| 16 |
|
| 17 |
+
# Clean string columns to replace invalid UTF-8 sequences
|
| 18 |
+
for col in df.select_dtypes(include=["object"]).columns:
|
| 19 |
+
df[col] = df[col].apply(
|
| 20 |
+
lambda x: x.encode("utf-8", errors="replace").decode("utf-8", errors="replace") if isinstance(x, str) else x
|
| 21 |
+
)
|
|
|
|
| 22 |
|
| 23 |
+
# Convert to JSON Lines
|
|
|
|
|
|
|
|
|
|
| 24 |
jsonl_data = df.to_json(orient="records", lines=True)
|
| 25 |
+
|
| 26 |
+
# Write the output to a file using UTF-8 encoding explicitly
|
| 27 |
output_file_path = "output.jsonl"
|
| 28 |
with open(output_file_path, "w", encoding="utf-8") as f:
|
| 29 |
f.write(jsonl_data)
|