Nolan Zandi Claude Sonnet 4.6 commited on
Commit
ad72587
·
1 Parent(s): 70b0712

fix: replace LFS-tracked CSV with a plain 100K-row sample

Browse files

LFS was silently serving the pointer file to HF Spaces instead of the
actual data, leaving the online_retail_data.csv unqueryable. Root cause:
HF Spaces does not reliably pull LFS objects for Space repos.

Changes:
- Replace 541K-row 45MB CSV with a random 100K-row 8.56MB sample;
retains full column set and date range, sufficient for all demos
- Remove samples/online_retail_data.csv from LFS tracking in .gitattributes
- Clean up historical-file-specific LFS entries from .gitattributes added
by the earlier lfs migrate (data_file.zip, data_source.db, etc.) since
those files no longer exist in the tree
- Also includes: table_generation_func now renders inline HTML in the
chat message instead of an iframe, adapting naturally to any screen width

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

.gitattributes CHANGED
@@ -33,14 +33,3 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
- samples/online_retail_data.csv filter=lfs diff=lfs merge=lfs -text
37
- data_file.zip filter=lfs diff=lfs merge=lfs -text
38
- data_source.db filter=lfs diff=lfs merge=lfs -text
39
- online_retail.db filter=lfs diff=lfs merge=lfs -text
40
- *.xlsx filter=lfs diff=lfs merge=lfs -text
41
- /Online_retail_AAA.zip filter=lfs diff=lfs merge=lfs -text
42
- /Online[[:space:]]Retail.xlsx filter=lfs diff=lfs merge=lfs -text
43
- /online_retail.db filter=lfs diff=lfs merge=lfs -text
44
- /data_file.zip filter=lfs diff=lfs merge=lfs -text
45
- /data_source.db filter=lfs diff=lfs merge=lfs -text
46
- /samples/online_retail_data.csv filter=lfs diff=lfs merge=lfs -text
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
functions/chart_functions.py CHANGED
@@ -356,30 +356,51 @@ def histogram_generation_func(x_column: str, session_hash, session_folder, y_col
356
 
357
  def table_generation_func(session_hash, session_folder, **kwargs):
358
  print("TABLE GENERATION")
359
- try:
 
 
360
  dir_path = TEMP_DIR / str(session_hash) / str(session_folder)
361
  csv_query_path = f'{dir_path}/query.csv'
362
- table_path = f'{dir_path}/table.html'
363
 
364
  df = pd.read_csv(csv_query_path)
365
 
366
- html_table = df.to_html()
367
- print(html_table[:1000])
368
-
369
- with open(table_path, "w") as file:
370
- file.write(html_table)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
 
372
- table_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/table.html'
373
-
374
- iframe = 'Please display this iframe: <div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + table_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
375
- print(iframe)
376
- return {"reply": iframe}
377
-
378
  except Exception as e:
379
- print("TABLE ERROR")
380
- print(e)
381
- reply = f"""There was an error generating the Pandas DataFrame table results.
382
- The error is {e},
383
- You should probably try again.
384
- """
385
- return {"reply": reply}
 
356
 
357
  def table_generation_func(session_hash, session_folder, **kwargs):
358
  print("TABLE GENERATION")
359
+ try:
360
+ from html import escape
361
+
362
  dir_path = TEMP_DIR / str(session_hash) / str(session_folder)
363
  csv_query_path = f'{dir_path}/query.csv'
 
364
 
365
  df = pd.read_csv(csv_query_path)
366
 
367
+ total_rows = len(df)
368
+ max_rows = 200
369
+ if total_rows > max_rows:
370
+ df = df.head(max_rows)
371
+ note = (f'<p class="vda-table-note">Showing first {max_rows} of {total_rows} rows'
372
+ ' — refine your query to see more specific results.</p>')
373
+ else:
374
+ note = ''
375
+
376
+ header_cells = ''.join(f'<th>{escape(str(col))}</th>' for col in df.columns)
377
+ row_html = [
378
+ '<tr>' + ''.join(f'<td>{escape(str(val))}</td>' for val in row) + '</tr>'
379
+ for _, row in df.iterrows()
380
+ ]
381
+
382
+ style = (
383
+ '<style>'
384
+ '.vda-table-wrap{overflow-x:auto;margin:8px 0;border-radius:8px;border:1px solid #e5e7eb;}'
385
+ '.vda-table{width:100%;border-collapse:collapse;font-size:13px;font-family:Inter,system-ui,sans-serif;}'
386
+ '.vda-table thead th{background:#3B82F6;color:#fff;padding:9px 14px;text-align:left;white-space:nowrap;font-weight:600;}'
387
+ '.vda-table tbody td{padding:7px 14px;border-bottom:1px solid #f1f5f9;white-space:nowrap;}'
388
+ '.vda-table tbody tr:nth-child(even){background:#f8fafc;}'
389
+ '.vda-table tbody tr:last-child td{border-bottom:none;}'
390
+ '.vda-table-note{font-size:12px;color:#6b7280;margin:4px 0 0;text-align:right;}'
391
+ '</style>'
392
+ )
393
+
394
+ table = (
395
+ '<div class="vda-table-wrap"><table class="vda-table">'
396
+ f'<thead><tr>{header_cells}</tr></thead>'
397
+ '<tbody>' + '\n'.join(row_html) + '</tbody>'
398
+ '</table></div>'
399
+ )
400
+
401
+ return {"reply": style + table + note}
402
 
 
 
 
 
 
 
403
  except Exception as e:
404
+ print("TABLE ERROR")
405
+ print(e)
406
+ return {"reply": f"There was an error generating the table. Error: {e}. You should probably try again."}
 
 
 
 
samples/online_retail_data.csv CHANGED
The diff for this file is too large to render. See raw diff