File size: 1,995 Bytes
f7c63a7
0921933
72d7898
f7c63a7
0921933
7c38ea9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119eea2
7c38ea9
119eea2
 
7c38ea9
0921933
7c38ea9
0921933
 
7c38ea9
 
 
6a1288a
 
 
7c38ea9
6a1288a
7c38ea9
 
 
 
 
 
 
 
6a1288a
7c38ea9
 
 
6a1288a
 
7c38ea9
c26932b
72d7898
0921933
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import gradio as gr
from typing import Dict, Any
from data_loader import read_dask_data, read_polars_data, read_another_dask_data

def load_and_process_data(dataset_choice: str, num_rows: int) -> Dict[str, Any]:
    """
    Load and process data based on the user's choice and specified number of rows.

    Args:
        dataset_choice (str): The dataset to load.
        num_rows (int): The number of rows to display.

    Returns:
        Dict[str, Any]: A dictionary containing the processed data or error message.
    """
    dataset_mapping = {
        "Dask Data": read_dask_data,
        "Polars Data": read_polars_data,
        "Another Dask Data": read_another_dask_data
    }

    data_loader = dataset_mapping.get(dataset_choice)
    if not data_loader:
        return {"error": "Invalid dataset choice."}

    try:
        data = data_loader()
        processed_data = data.head(num_rows)
        return {"processed_data": processed_data.to_dict()}
    except Exception as e:
        return {"error": f"Data processing failed: {str(e)}"}

def create_interface():
    """
    Create and launch the Gradio interface for data selection and display.
    """
    with gr.Blocks() as demo:
        gr.Markdown("# Enhanced Dataset Loader Demo")
        gr.Markdown("Interact with various datasets and select the amount of data to display.")

        with gr.Row():
            dataset_choice = gr.Dropdown(
                choices=["Dask Data", "Polars Data", "Another Dask Data"],
                label="Select Dataset"
            )
            num_rows = gr.Slider(
                minimum=1, maximum=100, value=5, label="Number of Rows to Display"
            )

        processed_data_output = gr.JSON(label="Processed Data")

        dataset_choice.render()
        num_rows.render()
        processed_data_output.render()

        demo.add(dataset_choice, num_rows, processed_data_output, load_and_process_data)

    demo.launch()

if __name__ == "__main__":
    create_interface()