chenyicheng commited on
Commit
dbe035b
·
1 Parent(s): 33a69ce

update app

Browse files
Files changed (1) hide show
  1. app.py +31 -17
app.py CHANGED
@@ -812,32 +812,46 @@ def _auto_suggest_datasets(task_description: str, benchmark_description: str) ->
812
  return [[d] for d in ds_ids]
813
 
814
 
 
 
 
 
 
 
 
 
 
 
 
 
815
  def _add_selected_suggestion(
816
- current: List[List[str]],
817
- suggestions: List[List[str]],
818
  idx: Optional[int],
819
  ) -> List[List[str]]:
820
- if idx is None or suggestions is None:
821
- return current
822
- if idx < 0 or idx >= len(suggestions):
823
- return current
824
- val = str(suggestions[idx][0]).strip()
825
  if not val:
826
- return current
827
- existing = [str(r[0]).strip() for r in (current or []) if r]
828
  if val in existing:
829
- return current
830
- return (current or []) + [[val]]
831
 
832
 
833
  def _add_all_suggestions(
834
- current: List[List[str]],
835
- suggestions: List[List[str]],
836
  ) -> List[List[str]]:
837
- existing = [str(r[0]).strip() for r in (current or []) if r]
838
- merged = list(current or [])
839
- for row in suggestions or []:
840
- val = str(row[0]).strip()
 
 
841
  if val and val not in existing:
842
  existing.append(val)
843
  merged.append([val])
 
812
  return [[d] for d in ds_ids]
813
 
814
 
815
+ def _rows(table) -> List[List[str]]:
816
+ """Normalize Gradio dataframe output (which may be pandas DataFrame) to list of rows."""
817
+ if table is None:
818
+ return []
819
+ if hasattr(table, "to_numpy"):
820
+ try:
821
+ return table.to_numpy().tolist()
822
+ except Exception:
823
+ return []
824
+ return table or []
825
+
826
+
827
  def _add_selected_suggestion(
828
+ current,
829
+ suggestions,
830
  idx: Optional[int],
831
  ) -> List[List[str]]:
832
+ rows_current = _rows(current)
833
+ rows_suggestions = _rows(suggestions)
834
+ if idx is None or idx < 0 or idx >= len(rows_suggestions):
835
+ return rows_current
836
+ val = str(rows_suggestions[idx][0]).strip() if rows_suggestions[idx] else ""
837
  if not val:
838
+ return rows_current
839
+ existing = [str(r[0]).strip() for r in rows_current if r and len(r) > 0]
840
  if val in existing:
841
+ return rows_current
842
+ return rows_current + [[val]]
843
 
844
 
845
  def _add_all_suggestions(
846
+ current,
847
+ suggestions,
848
  ) -> List[List[str]]:
849
+ rows_current = _rows(current)
850
+ rows_suggestions = _rows(suggestions)
851
+ existing = [str(r[0]).strip() for r in rows_current if r and len(r) > 0]
852
+ merged = list(rows_current)
853
+ for row in rows_suggestions:
854
+ val = str(row[0]).strip() if row else ""
855
  if val and val not in existing:
856
  existing.append(val)
857
  merged.append([val])