Spaces:
Runtime error
Runtime error
ryanlinjui
commited on
Commit
•
f5b7605
1
Parent(s):
2de302a
fix: input chart file different encode issue
Browse files- app.py +8 -2
- pyproject.toml +1 -0
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import json, re
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
|
|
4 |
|
5 |
from taiko import (
|
6 |
preprocess,
|
@@ -31,10 +32,15 @@ def txt_loads(data_str:str):
|
|
31 |
return output_data
|
32 |
|
33 |
def handle(chart_path:str, music_path:str):
|
|
|
|
|
|
|
|
|
|
|
34 |
if chart_path.endswith(".json"):
|
35 |
-
data = json.loads(open(chart_path, "r").read())
|
36 |
elif chart_path.endswith(".txt"):
|
37 |
-
data = txt_loads(open(chart_path, "r").read())
|
38 |
|
39 |
if len(data["data"]) < 0 and len(data["data"]) > 5:
|
40 |
raise("Issue occur: chart data")
|
|
|
1 |
import json, re
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
+
import chardet
|
5 |
|
6 |
from taiko import (
|
7 |
preprocess,
|
|
|
32 |
return output_data
|
33 |
|
34 |
def handle(chart_path:str, music_path:str):
|
35 |
+
with open(chart_path, "rb") as file:
|
36 |
+
raw_data = file.read(4096)
|
37 |
+
result = chardet.detect(raw_data)
|
38 |
+
encoding = result["encoding"]
|
39 |
+
|
40 |
if chart_path.endswith(".json"):
|
41 |
+
data = json.loads(open(chart_path, "r", encoding=encoding).read())
|
42 |
elif chart_path.endswith(".txt"):
|
43 |
+
data = txt_loads(open(chart_path, "r", encoding=encoding).read())
|
44 |
|
45 |
if len(data["data"]) < 0 and len(data["data"]) > 5:
|
46 |
raise("Issue occur: chart data")
|
pyproject.toml
CHANGED
@@ -9,6 +9,7 @@ packages = [{include = "taiko_music_generator"}]
|
|
9 |
[tool.poetry.dependencies]
|
10 |
python = "^3.10"
|
11 |
gradio = "^4.19.2"
|
|
|
12 |
|
13 |
|
14 |
[build-system]
|
|
|
9 |
[tool.poetry.dependencies]
|
10 |
python = "^3.10"
|
11 |
gradio = "^4.19.2"
|
12 |
+
chardet = "^5.2.0"
|
13 |
|
14 |
|
15 |
[build-system]
|