Kilos1 commited on
Commit
b422128
·
verified ·
1 Parent(s): f67e096

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -0
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import supabase
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+ import gradio as gr
6
+ import io
7
+
8
+ client = supabase.create_client(
9
+ "https://uddbzgupnpujsabrgbyk.supabase.co",
10
+ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVkZGJ6Z3VwbnB1anNhYnJnYnlrIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTcxODgxOTE3NywiZXhwIjoyMDM0Mzk1MTc3fQ.OH-NJ64dHhr0WPMZU05TsSBfRkoiX29W_cFHYqnN0us"
11
+
12
+ )
13
+ def read_data():
14
+ response = client.table('Plant Growth Analysis').select("*").execute()
15
+ df = pd.DataFrame(response.data)
16
+ return df
17
+
18
+ df = read_data()
19
+ #df.head()
20
+
21
+ # Convert LoyaltyProgram to categorical
22
+ #df['Growth_Milestone'] = df['Growth_Milestone'].map({0: 'No', 1: 'Yes'})
23
+
24
+ # Function to create histogram
25
+ def create_histogram(column):
26
+ plt.figure(figsize=(10, 6))
27
+ sns.histplot(data=df, x=column, kde=True)
28
+ plt.title(f'Histogram of {column}')
29
+ plt.xlabel(column)
30
+ plt.ylabel('Count')
31
+ return plt
32
+
33
+ # Function to create scatter plot
34
+ def create_scatter(x_column, y_column, hue_column):
35
+ plt.figure(figsize=(10, 6))
36
+ sns.scatterplot(data=df, x=x_column, y=y_column, hue=hue_column)
37
+ plt.title(f'{x_column} vs {y_column} (colored by {hue_column})')
38
+ plt.xlabel(x_column)
39
+ plt.ylabel(y_column)
40
+ return plt
41
+
42
+ # Function to create box plot
43
+ def create_boxplot(x_column, y_column):
44
+ plt.figure(figsize=(10, 6))
45
+ sns.boxplot(data=df, x=x_column, y=y_column)
46
+ plt.title(f'Box Plot of {y_column} by {x_column}')
47
+ plt.xlabel(x_column)
48
+ plt.ylabel(y_column)
49
+ return plt
50
+
51
+ # Function to create bar plot
52
+ def create_barplot(x_column, y_column):
53
+ plt.figure(figsize=(10, 6))
54
+ sns.barplot(data=df, x=x_column, y=y_column)
55
+ plt.title(f'Bar Plot of {y_column} by {x_column}')
56
+ plt.xlabel(x_column)
57
+ plt.ylabel(y_column)
58
+ plt.xticks(rotation=45)
59
+ return plt
60
+
61
+ #Function to create Line Plot
62
+ def create_lineplot(x_column, y_column):
63
+ plt.figure(figsize=(10, 6))
64
+ sns.lineplot(data=df,x=x_column, y=y_column)
65
+ plt.title(f'Line Plot of {y_column} vs {x_column}')
66
+ plt.xlabel(x_column)
67
+ plt.ylabel(y_column)
68
+ return plt
69
+
70
+ # Gradio interface
71
+ def visualize(plot_type, x_column, y_column, hue_column):
72
+ if plot_type == "Histogram":
73
+ return create_histogram(x_column)
74
+ elif plot_type == "Scatter Plot":
75
+ return create_scatter(x_column, y_column, hue_column)
76
+ elif plot_type == "Box Plot":
77
+ return create_boxplot(x_column, y_column)
78
+ elif plot_type == "Bar Plot":
79
+ return create_barplot(x_column, y_column)
80
+ elif plot_type == "Line Plot":
81
+ return create_lineplot(x_column, y_column)
82
+
83
+ # Create Gradio interface
84
+ iface = gr.Interface(
85
+ fn=visualize,
86
+ inputs=[
87
+ gr.Dropdown(["Histogram", "Scatter Plot", "Box Plot", "Bar Plot","Line Plot"], label="Plot Type"),
88
+ gr.Dropdown(df.columns.tolist(), label="X-axis"),
89
+ gr.Dropdown(df.columns.tolist(), label="Y-axis"),
90
+ gr.Dropdown(df.columns.tolist(), label="Hue (for Scatter Plot/Line Plot)")
91
+
92
+ ],
93
+ outputs="plot",
94
+ title="Plant Growth Data Visualization Dashboard",
95
+ description="This dashboard displays various visualizations of the plant growth dataset.",
96
+ )
97
+
98
+ # Launch the interface
99
+ iface.launch()
100
+
101
+
102
+
103
+