S-Dreamer commited on
Commit
0921933
·
verified ·
1 Parent(s): 72d7898

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -21
app.py CHANGED
@@ -1,29 +1,52 @@
1
  # Import necessary libraries
2
  import gradio as gr
 
3
  from data_loader import read_dask_data, read_polars_data, read_another_dask_data
4
 
5
- # Function to handle the data loading logic
6
- def load_and_display_data():
7
- # Load datasets
8
- dask_data = read_dask_data()
9
- polars_data = read_polars_data()
10
- another_dask_data = read_another_dask_data()
 
 
 
 
 
 
 
 
 
11
 
12
- # Optionally process data (e.g., filter, summarize)
13
- # Display the first few rows of the datasets
14
- return {
15
- "Dask Data from Codeforces Python Submissions": dask_data.head(),
16
- "Polars Data from Python Reasoning Dataset": polars_data.head(),
17
- "Another Dask Data from Python Github Code": another_dask_data.head()
18
- }
19
 
20
- # Create a Gradio interface to display the data
21
- demo = gr.Interface(
22
- load_and_display_data,
23
- inputs=[], # No inputs for this simple demo
24
- outputs="json", # Display output as a JSON to show data head
25
- title="Dataset Loader Demo",
26
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- if __name__ == "__main__":
29
  demo.launch()
 
 
 
 
1
  # Import necessary libraries
2
  import gradio as gr
3
+ from typing import Dict, Any
4
  from data_loader import read_dask_data, read_polars_data, read_another_dask_data
5
 
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
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
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(
41
+ fn=load_and_process_data,
42
+ inputs=[dataset_choice, num_rows], # User can select dataset and number of rows
43
+ outputs="json", # Display output as JSON
44
+ title="Enhanced Dataset Loader Demo",
45
+ description="Interact with various datasets and select the amount of data to display.",
46
+ allow_flagging="never" # Disable flagging if not needed
47
+ )
48
 
 
49
  demo.launch()
50
+
51
+ if __name__ == "__main__":
52
+ create_interface()