FahadAlam's picture
Update app.py
f315c6b
raw history blame
No virus
2.29 kB
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)