asahi417 commited on
Commit
6171564
1 Parent(s): ab289ef
Files changed (1) hide show
  1. download_audio.py +11 -3
download_audio.py CHANGED
@@ -69,12 +69,20 @@ def get_metadata():
69
  return df.sort_values(by=["line_no", "side"])
70
 
71
 
 
 
 
 
 
 
 
 
72
  def get_audio(dataframe: pd.DataFrame):
73
- features = {"line_no": dataframe.pop('line_no').values[0]}
74
  for side, df in dataframe.groupby("side"):
75
  df.pop("side")
76
- features.update({f"{side}.{k}": v for k, v in df.iloc[0].to_dict().items()})
77
- features[f"{side}.path"] = p_join(cache_dir_audio, os.path.basename(features[f"{side}.url"]))
78
  if not os.path.exists(features[f"{side}.path"]):
79
  if not wget(features[f"{side}.url"], output_file=features[f"{side}.path"]):
80
  return False
 
69
  return df.sort_values(by=["line_no", "side"])
70
 
71
 
72
+ def to_json_serializable(val):
73
+ if "float" in str(type(val)):
74
+ return float(val)
75
+ if "int" in str(type(val)):
76
+ return int(val)
77
+ return str(val)
78
+
79
+
80
  def get_audio(dataframe: pd.DataFrame):
81
+ features = {"line_no": int(dataframe.pop('line_no').values[0])}
82
  for side, df in dataframe.groupby("side"):
83
  df.pop("side")
84
+ features.update({f"{side}.{k}": to_json_serializable(v) for k, v in df.iloc[0].to_dict().items()})
85
+ features[f"{side}.path"] = str(p_join(cache_dir_audio, os.path.basename(features[f"{side}.url"])))
86
  if not os.path.exists(features[f"{side}.path"]):
87
  if not wget(features[f"{side}.url"], output_file=features[f"{side}.path"]):
88
  return False