S-Dreamer commited on
Commit
119eea2
·
verified ·
1 Parent(s): 60af199

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -6,24 +6,24 @@ from data_loader import read_dask_data, read_polars_data, read_another_dask_data
6
  # Function to handle the data loading and processing logic
7
  def load_and_process_data(dataset_choice: str, num_rows: int) -> Dict[str, Any]:
8
  try:
9
- # Load and process datasets based on user choice
10
- if dataset_choice == "Dask Data":
11
- data = read_dask_data()
12
- processed_data = data.head(num_rows)
13
- elif dataset_choice == "Polars Data":
14
- data = read_polars_data()
15
- processed_data = data.head(num_rows)
16
- elif dataset_choice == "Another Dask Data":
17
- data = read_another_dask_data()
18
- processed_data = data.head(num_rows)
19
- else:
20
  return {"error": "Invalid dataset choice."}
21
 
22
- # Optionally, include more complex data processing here
 
 
23
 
24
- # Return the processed data
25
  return {
26
- "Processed Data": processed_data
27
  }
28
  except Exception as e:
29
  # Log the exception
@@ -32,9 +32,14 @@ def load_and_process_data(dataset_choice: str, num_rows: int) -> Dict[str, Any]:
32
 
33
  # Create a Gradio interface with more features
34
  def create_interface():
35
- # Interface inputs
36
- dataset_choice = gr.inputs.Dropdown(["Dask Data", "Polars Data", "Another Dask Data"], label="Select Dataset")
37
- num_rows = gr.inputs.Slider(minimum=1, maximum=100, default=5, label="Number of Rows to Display")
 
 
 
 
 
38
 
39
  # Interface definition
40
  demo = gr.Interface(
 
6
  # Function to handle the data loading and processing logic
7
  def load_and_process_data(dataset_choice: str, num_rows: int) -> Dict[str, Any]:
8
  try:
9
+ # Load datasets based on user choice
10
+ dataset_mapping = {
11
+ "Dask Data": read_dask_data,
12
+ "Polars Data": read_polars_data,
13
+ "Another Dask Data": read_another_dask_data
14
+ }
15
+
16
+ # Fetch the chosen dataset using the mapping
17
+ data_loader = dataset_mapping.get(dataset_choice)
18
+ if not data_loader:
 
19
  return {"error": "Invalid dataset choice."}
20
 
21
+ # Process data to show the specified number of rows
22
+ data = data_loader()
23
+ processed_data = data.head(num_rows)
24
 
 
25
  return {
26
+ "Processed Data": processed_data.to_dict() # Convert DataFrame to dictionary for JSON serialization
27
  }
28
  except Exception as e:
29
  # Log the exception
 
32
 
33
  # Create a Gradio interface with more features
34
  def create_interface():
35
+ # Interface inputs (updated for Gradio v5.x)
36
+ dataset_choice = gr.Dropdown(
37
+ choices=["Dask Data", "Polars Data", "Another Dask Data"],
38
+ label="Select Dataset"
39
+ )
40
+ num_rows = gr.Slider(
41
+ minimum=1, maximum=100, default=5, label="Number of Rows to Display"
42
+ )
43
 
44
  # Interface definition
45
  demo = gr.Interface(