lhoestq HF staff commited on
Commit
5503ee2
1 Parent(s): b99ef2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -6,7 +6,10 @@ con = duckdb.connect(":memory:")
6
  def greet(SQL_Query):
7
  if "limit" not in SQL_Query.lower():
8
  raise gr.Error("You should use the LIMIT clause or it may take too much time to run your query. For example: ```LIMIT 10000```")
9
- return con.sql(SQL_Query).df().apply(lambda x: x.apply(lambda y: y[:50] + "..." if isinstance(y, str) and len(y) > 50 else y))
 
 
 
10
 
11
  examples = [
12
  "SELECT * FROM 'hf://datasets/HuggingFaceFW/fineweb/sample/10BT/*.parquet' LIMIT 10;",
 
6
  def greet(SQL_Query):
7
  if "limit" not in SQL_Query.lower():
8
  raise gr.Error("You should use the LIMIT clause or it may take too much time to run your query. For example: ```LIMIT 10000```")
9
+ df = con.sql(SQL_Query).df()
10
+ if df.columns: # truncate long strings
11
+ df = df.apply(lambda x: x.apply(lambda y: y[:150 // len(df.columns)] + "..." if isinstance(y, str) and len(y) > 150 // len(df.columns) else y))
12
+ return df
13
 
14
  examples = [
15
  "SELECT * FROM 'hf://datasets/HuggingFaceFW/fineweb/sample/10BT/*.parquet' LIMIT 10;",