import supabase import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import gradio as gr import io client = supabase.create_client( "https://uddbzgupnpujsabrgbyk.supabase.co", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVkZGJ6Z3VwbnB1anNhYnJnYnlrIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTcxODgxOTE3NywiZXhwIjoyMDM0Mzk1MTc3fQ.OH-NJ64dHhr0WPMZU05TsSBfRkoiX29W_cFHYqnN0us" ) def read_data(): response = client.table('Plant Growth Analysis').select("*").execute() df = pd.DataFrame(response.data) return df df = read_data() #df.head() # Convert LoyaltyProgram to categorical #df['Growth_Milestone'] = df['Growth_Milestone'].map({0: 'No', 1: 'Yes'}) # Function to create histogram def create_histogram(column): plt.figure(figsize=(10, 6)) sns.histplot(data=df, x=column, kde=True) plt.title(f'Histogram of {column}') plt.xlabel(column) plt.ylabel('Count') return plt # Function to create scatter plot def create_scatter(x_column, y_column, hue_column): plt.figure(figsize=(10, 6)) sns.scatterplot(data=df, x=x_column, y=y_column, hue=hue_column) plt.title(f'{x_column} vs {y_column} (colored by {hue_column})') plt.xlabel(x_column) plt.ylabel(y_column) return plt # Function to create box plot def create_boxplot(x_column, y_column): plt.figure(figsize=(10, 6)) sns.boxplot(data=df, x=x_column, y=y_column) plt.title(f'Box Plot of {y_column} by {x_column}') plt.xlabel(x_column) plt.ylabel(y_column) return plt # Function to create bar plot def create_barplot(x_column, y_column): plt.figure(figsize=(10, 6)) sns.barplot(data=df, x=x_column, y=y_column) plt.title(f'Bar Plot of {y_column} by {x_column}') plt.xlabel(x_column) plt.ylabel(y_column) plt.xticks(rotation=45) return plt #Function to create Line Plot def create_lineplot(x_column, y_column): plt.figure(figsize=(10, 6)) sns.lineplot(data=df,x=x_column, y=y_column) plt.title(f'Line Plot of {y_column} vs {x_column}') plt.xlabel(x_column) plt.ylabel(y_column) return plt # Gradio interface def visualize(plot_type, x_column, y_column, hue_column): if plot_type == "Histogram": return create_histogram(x_column) elif plot_type == "Scatter Plot": return create_scatter(x_column, y_column, hue_column) elif plot_type == "Box Plot": return create_boxplot(x_column, y_column) elif plot_type == "Bar Plot": return create_barplot(x_column, y_column) elif plot_type == "Line Plot": return create_lineplot(x_column, y_column) # Create Gradio interface iface = gr.Interface( fn=visualize, inputs=[ gr.Dropdown(["Histogram", "Scatter Plot", "Box Plot", "Bar Plot","Line Plot"], label="Plot Type"), gr.Dropdown(df.columns.tolist(), label="X-axis"), gr.Dropdown(df.columns.tolist(), label="Y-axis"), gr.Dropdown(df.columns.tolist(), label="Hue (for Scatter Plot/Line Plot)") ], outputs="plot", title="Plant Growth Data Visualization Dashboard", description="This dashboard displays various visualizations of the plant growth dataset.", ) # Launch the interface iface.launch()