FahadAlam's picture
Create new file
9a46f43
raw history blame
No virus
2.24 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()
plot1 = plt.figure()
if hue:
sns.histplot(data = df, x = df[feature], kde = True, hue = hue)
else:
sns.histplot(data = df, x = df[feature], kde = True)
if feature in non_numeric_cols:
plot2 = plt.figure()
if hue:
sns.countplot(x = df[feature], data = df, palette='rainbow', hue = hue)
else:
sns.countplot(x = df[feature], data = df, palette='rainbow')
else:
plot2 = plt.figure()
if hue:
sns.boxplot(x = df[feature], hue = hue)
else:
sns.boxplot(x = df[feature])
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("""### Visualizations""")
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)