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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -23,34 +23,35 @@ def load_and_process_data(dataset_choice: str, num_rows: int) -> Dict[str, Any]:
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
30
  print(f"Error processing data: {str(e)}")
31
  return {"error": "Unable to process data. Please check the logs for details."}
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(
46
- fn=load_and_process_data,
47
- inputs=[dataset_choice, num_rows], # User can select dataset and number of rows
48
- outputs="json", # Display output as JSON
49
- title="Enhanced Dataset Loader Demo",
50
- description="Interact with various datasets and select the amount of data to display.",
51
- allow_flagging="never" # Disable flagging if not needed
52
- )
53
-
 
54
  demo.launch()
55
 
56
  if __name__ == "__main__":
 
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
30
  print(f"Error processing data: {str(e)}")
31
  return {"error": "Unable to process data. Please check the logs for details."}
32
 
33
+ # Create a Gradio interface with updated components
34
  def create_interface():
35
+ # Interface inputs
36
+ dataset_choice = gr.components.Dropdown(
37
  choices=["Dask Data", "Polars Data", "Another Dask Data"],
38
  label="Select Dataset"
39
  )
40
+ num_rows = gr.components.Slider(
41
+ minimum=1, maximum=100, value=5, label="Number of Rows to Display"
42
  )
43
 
44
  # Interface definition
45
+ with gr.Blocks() as demo:
46
+ gr.Markdown("# Enhanced Dataset Loader Demo")
47
+ gr.Markdown("Interact with various datasets and select the amount of data to display.")
48
+ with gr.Row():
49
+ dataset_choice.render()
50
+ num_rows.render()
51
+ processed_data_output = gr.JSON(label="Processed Data")
52
+ processed_data_output.render()
53
+
54
+ demo.add(dataset_choice, num_rows, processed_data_output, load_and_process_data)
55
  demo.launch()
56
 
57
  if __name__ == "__main__":