lhoestq HF staff commited on
Commit
de383a5
·
1 Parent(s): 4482b40

improve parsing

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -399,15 +399,14 @@ with gr.Blocks(css=css) as demo:
399
 
400
  def parse_csv_df(csv: str, csv_header: Optional[str] = None) -> pd.DataFrame:
401
  # Fix generation mistake when providing a list that is not in quotes
402
- if ",[" in csv:
403
- for match in re.finditer(r'\[("[\w ]+"[, ]?)+\]', csv):
404
- span = match.string[match.start() : match.end()]
405
- csv = csv.replace(span, '"' + span.replace('"', "'") + '"')
406
  # Add header if missing
407
  if csv_header and csv.strip().split("\n")[0] != csv_header:
408
  csv = csv_header + "\n" + csv
409
  # Read CSV
410
- df = pd.read_csv(io.StringIO(csv))
411
  return df
412
 
413
 
 
399
 
400
  def parse_csv_df(csv: str, csv_header: Optional[str] = None) -> pd.DataFrame:
401
  # Fix generation mistake when providing a list that is not in quotes
402
+ for match in re.finditer(r'\[("[\w ]+"[, ]?)+\]', csv):
403
+ span = match.string[match.start() : match.end()]
404
+ csv = csv.replace(span, '"' + span.replace('"', "'") + '"')
 
405
  # Add header if missing
406
  if csv_header and csv.strip().split("\n")[0] != csv_header:
407
  csv = csv_header + "\n" + csv
408
  # Read CSV
409
+ df = pd.read_csv(io.StringIO(csv), skipinitialspace=True)
410
  return df
411
 
412