datasciencedojo commited on
Commit
47646a2
·
1 Parent(s): 2e6f218

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +83 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import pandas as pd
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+
7
+
8
+ def dataset_change(dataset):
9
+ df = pd.read_csv(dataset.name)
10
+ features = df.columns
11
+ features_object_list = [feature for feature in features]
12
+ describe = df.describe(include='all')
13
+ print(describe)
14
+ return describe.reset_index(), gr.Dropdown.update(choices = features_object_list), gr.Dropdown.update(choices = features_object_list)
15
+
16
+ def feature_select(dataset, feature, hue = None):
17
+ df = pd.read_csv(dataset.name)
18
+ non_numeric_cols = df.select_dtypes('object').columns.tolist()
19
+
20
+ if feature in non_numeric_cols:
21
+ kde = False
22
+ plot2 = plt.figure()
23
+ if hue:
24
+ sns.countplot(x = feature, data = df, palette='rainbow', hue = hue)
25
+ else:
26
+ sns.countplot(x = feature, data = df, palette='rainbow')
27
+ else:
28
+ kde = True
29
+ plot2 = plt.figure()
30
+ if hue:
31
+ sns.boxplot(x = feature, data = df, hue = hue)
32
+ else:
33
+ sns.boxplot(x = feature, data = df )
34
+
35
+ plot1 = plt.figure()
36
+ if hue:
37
+ sns.histplot(data = df, x = feature, kde = kde, hue = hue, multiple="stack")
38
+ else:
39
+ sns.histplot(data = df, x = feature, kde = kde)
40
+
41
+
42
+ return plot1, plot2
43
+
44
+
45
+ with gr.Blocks() as demo:
46
+ gr.Markdown("""## Input Dataset""")
47
+ with gr.Row():
48
+ dataset = gr.File()
49
+ with gr.Row():
50
+ dataframe = gr.Dataframe()
51
+ gr.Markdown("""## Select the feature to visualize""")
52
+ with gr.Row():
53
+ with gr.Column():
54
+ features = gr.Dropdown(label="Select feature to visualize")
55
+ with gr.Column():
56
+ hue = gr.Dropdown(label="Select hue")
57
+ with gr.Row():
58
+ btn = gr.Button("Visualize")
59
+
60
+ gr.Markdown("""## Visualization""")
61
+ with gr.Row():
62
+ plot1 = gr.Plot()
63
+ with gr.Row():
64
+ plot2 = gr.Plot()
65
+
66
+ gr.Examples(
67
+ examples=[],
68
+ fn = dataset_change,
69
+ inputs = dataset,
70
+ outputs = [dataframe, features, hue]
71
+ )
72
+
73
+ dataset.change(fn=dataset_change,
74
+ inputs = dataset,
75
+ outputs = [dataframe, features, hue]
76
+ )
77
+
78
+ btn.click(fn=feature_select,
79
+ inputs=[dataset, features, hue],
80
+ outputs=[plot1, plot2]
81
+ )
82
+
83
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ seaborn