vkapoor commited on
Commit
f03b2d1
·
1 Parent(s): e27cba6

add example csv

Browse files
Files changed (1) hide show
  1. app.py +47 -18
app.py CHANGED
@@ -11,24 +11,31 @@ import matplotlib.pyplot as plt
11
  import numpy as np
12
  import pandas as pd
13
 
14
- from entra import DataFrameTransformer
15
 
16
  matplotlib.use("Agg")
17
 
18
 
19
  def generate_uniform_data(n_per_dim: int = 20, dimensions: int = 2) -> pd.DataFrame:
20
- """Generate uniform grid data."""
21
  if dimensions == 2:
22
- x = np.linspace(-10, 10, n_per_dim)
23
- y = np.linspace(-10, 10, n_per_dim)
24
- xx, yy = np.meshgrid(x, y)
25
- df = pd.DataFrame({"x": xx.ravel(), "y": yy.ravel()})
26
  else: # 3D
27
- x = np.linspace(-10, 10, n_per_dim)
28
- y = np.linspace(-10, 10, n_per_dim)
29
- z = np.linspace(-10, 10, n_per_dim)
30
- xx, yy, zz = np.meshgrid(x, y, z)
31
- df = pd.DataFrame({"x": xx.ravel(), "y": yy.ravel(), "z": zz.ravel()})
 
 
 
 
 
 
 
 
 
 
32
  return df
33
 
34
 
@@ -346,13 +353,29 @@ def create_app():
346
  with gr.Column(scale=1):
347
  gr.Markdown("### Step 1: Load or Generate Data")
348
 
349
- with gr.Accordion("Option A: Upload CSV", open=True):
350
- file_upload = gr.File(
351
- label="Upload CSV file", file_types=[".csv"]
352
- )
353
- upload_btn = gr.Button("Load CSV", variant="secondary")
 
 
 
 
 
 
 
 
 
 
 
354
 
355
- with gr.Accordion("Option B: Generate Uniform Data", open=True):
 
 
 
 
 
356
  n_per_dim = gr.Slider(
357
  minimum=5,
358
  maximum=50,
@@ -365,10 +388,16 @@ def create_app():
365
  )
366
  generate_btn = gr.Button(
367
  "Generate Uniform Distribution",
368
- variant="secondary",
369
  )
370
  download_file = gr.File(label="Download generated CSV")
371
 
 
 
 
 
 
 
372
  data_info = gr.Textbox(
373
  label="Data Info", lines=8, interactive=False
374
  )
 
11
  import numpy as np
12
  import pandas as pd
13
 
14
+ from entra import DataFrameTransformer, VectorSampler
15
 
16
  matplotlib.use("Agg")
17
 
18
 
19
  def generate_uniform_data(n_per_dim: int = 20, dimensions: int = 2) -> pd.DataFrame:
20
+ """Generate uniform grid data using VectorSampler."""
21
  if dimensions == 2:
22
+ center = [0.0, 0.0]
 
 
 
23
  else: # 3D
24
+ center = [0.0, 0.0, 0.0]
25
+
26
+ sampler = VectorSampler(
27
+ center=center,
28
+ delta_x=1,
29
+ num_points_per_dim=n_per_dim,
30
+ distribution="uniform",
31
+ )
32
+ points = sampler.sample()
33
+
34
+ if dimensions == 2:
35
+ df = pd.DataFrame({"x": points[:, 0], "y": points[:, 1]})
36
+ else:
37
+ df = pd.DataFrame({"x": points[:, 0], "y": points[:, 1], "z": points[:, 2]})
38
+
39
  return df
40
 
41
 
 
353
  with gr.Column(scale=1):
354
  gr.Markdown("### Step 1: Load or Generate Data")
355
 
356
+ gr.Markdown(
357
+ """
358
+ **No CSV file?** Use "Generate Sample Data" below to create a uniform grid.
359
+
360
+ **Have your own CSV?** Format requirements:
361
+ - Header row with column names
362
+ - Numeric columns for coordinates (e.g., `x`, `y`, `z`)
363
+ - Example:
364
+ ```
365
+ x,y
366
+ -9.5,-9.5
367
+ -9.5,-8.5
368
+ ...
369
+ ```
370
+ """
371
+ )
372
 
373
+ with gr.Accordion(
374
+ "Generate Sample Data (no CSV needed)", open=True
375
+ ):
376
+ gr.Markdown(
377
+ "*Creates a uniform grid using VectorSampler - perfect for testing*"
378
+ )
379
  n_per_dim = gr.Slider(
380
  minimum=5,
381
  maximum=50,
 
388
  )
389
  generate_btn = gr.Button(
390
  "Generate Uniform Distribution",
391
+ variant="primary",
392
  )
393
  download_file = gr.File(label="Download generated CSV")
394
 
395
+ with gr.Accordion("Upload Your Own CSV", open=False):
396
+ file_upload = gr.File(
397
+ label="Upload CSV file", file_types=[".csv"]
398
+ )
399
+ upload_btn = gr.Button("Load CSV", variant="secondary")
400
+
401
  data_info = gr.Textbox(
402
  label="Data Info", lines=8, interactive=False
403
  )