Spaces:
Build error
Build error
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
plot1 = plt.figure()
|
21 |
+
if hue:
|
22 |
+
sns.histplot(data = df, x = df[feature], kde = True, hue = hue)
|
23 |
+
else:
|
24 |
+
sns.histplot(data = df, x = df[feature], kde = True)
|
25 |
+
|
26 |
+
if feature in non_numeric_cols:
|
27 |
+
plot2 = plt.figure()
|
28 |
+
if hue:
|
29 |
+
sns.countplot(x = df[feature], data = df, palette='rainbow', hue = hue)
|
30 |
+
else:
|
31 |
+
sns.countplot(x = df[feature], data = df, palette='rainbow')
|
32 |
+
else:
|
33 |
+
plot2 = plt.figure()
|
34 |
+
if hue:
|
35 |
+
sns.boxplot(x = df[feature], hue = hue)
|
36 |
+
else:
|
37 |
+
sns.boxplot(x = df[feature])
|
38 |
+
|
39 |
+
return plot1, plot2
|
40 |
+
|
41 |
+
|
42 |
+
with gr.Blocks() as demo:
|
43 |
+
gr.Markdown("""### Input Dataset""")
|
44 |
+
with gr.Row():
|
45 |
+
dataset = gr.File()
|
46 |
+
with gr.Row():
|
47 |
+
dataframe = gr.Dataframe()
|
48 |
+
gr.Markdown("""### Select the feature to visualize""")
|
49 |
+
with gr.Row():
|
50 |
+
with gr.Column():
|
51 |
+
features = gr.Dropdown(label="Select feature to visualize")
|
52 |
+
with gr.Column():
|
53 |
+
hue = gr.Dropdown(label="Select hue")
|
54 |
+
with gr.Row():
|
55 |
+
btn = gr.Button("Visualize")
|
56 |
+
|
57 |
+
gr.Markdown("""### Visualizations""")
|
58 |
+
with gr.Row():
|
59 |
+
plot1 = gr.Plot()
|
60 |
+
with gr.Row():
|
61 |
+
plot2 = gr.Plot()
|
62 |
+
|
63 |
+
gr.Examples(
|
64 |
+
examples=[],
|
65 |
+
fn = dataset_change,
|
66 |
+
inputs = dataset,
|
67 |
+
outputs = [dataframe, features, hue]
|
68 |
+
)
|
69 |
+
|
70 |
+
dataset.change(fn=dataset_change,
|
71 |
+
inputs = dataset,
|
72 |
+
outputs = [dataframe, features, hue]
|
73 |
+
)
|
74 |
+
|
75 |
+
btn.click(fn=feature_select,
|
76 |
+
inputs=[dataset, features, hue],
|
77 |
+
outputs=[plot1, plot2]
|
78 |
+
)
|
79 |
+
|
80 |
+
demo.launch(debug=True)
|