File size: 2,288 Bytes
9a46f43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e35e1d0
9a46f43
 
e35e1d0
9a46f43
e35e1d0
9a46f43
e35e1d0
9a46f43
 
e35e1d0
9a46f43
e35e1d0
 
 
 
 
 
 
 
9a46f43
 
 
 
 
f315c6b
9a46f43
 
 
 
f315c6b
9a46f43
 
 
 
 
 
 
 
f315c6b
9a46f43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import gradio as gr
import os
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt


def dataset_change(dataset):   
    df = pd.read_csv(dataset.name)
    features = df.columns
    features_object_list = [feature for feature in features]
    describe = df.describe(include='all')
    print(describe)
    return describe.reset_index(), gr.Dropdown.update(choices = features_object_list), gr.Dropdown.update(choices = features_object_list)

def feature_select(dataset, feature, hue = None):
    df = pd.read_csv(dataset.name)
    non_numeric_cols = df.select_dtypes('object').columns.tolist()
    
    if feature in non_numeric_cols:
      kde = False
      plot2 = plt.figure()
      if hue:
        sns.countplot(x = feature, data = df, palette='rainbow', hue = hue)
      else:
        sns.countplot(x = feature, data = df, palette='rainbow')
    else:
      kde = True
      plot2 = plt.figure()
      if hue:
        sns.boxplot(x = feature, data = df, hue = hue)
      else:
        sns.boxplot(x = feature, data = df )

    plot1 = plt.figure()
    if hue:
      sns.histplot(data = df, x = feature, kde = kde, hue = hue, multiple="stack")
    else:
      sns.histplot(data = df, x = feature, kde = kde)
   

    return plot1, plot2


with gr.Blocks() as demo:
    gr.Markdown("""## Input Dataset""")
    with gr.Row():
        dataset = gr.File()
    with gr.Row():
        dataframe = gr.Dataframe()
    gr.Markdown("""## Select the feature to visualize""")
    with gr.Row():
      with gr.Column():
        features = gr.Dropdown(label="Select feature to visualize")
      with gr.Column():
        hue = gr.Dropdown(label="Select hue")
    with gr.Row():
      btn = gr.Button("Visualize")

    gr.Markdown("""## Visualization""")
    with gr.Row():
        plot1 = gr.Plot()
    with gr.Row():
        plot2 = gr.Plot()
    
    gr.Examples(
          examples=[],
          fn = dataset_change,
          inputs = dataset, 
          outputs = [dataframe, features, hue]
          )

    dataset.change(fn=dataset_change, 
        inputs = dataset, 
        outputs = [dataframe, features, hue]
        )
    
    btn.click(fn=feature_select, 
        inputs=[dataset, features, hue],
        outputs=[plot1, plot2]
        )
    
demo.launch(debug=True)