Spaces:
Sleeping
Sleeping
bad
Browse files- .gitignore +1 -0
- app.py +17 -0
- grid_search_tab.py +117 -0
- requirements.txt +3 -0
- theme_config.py +167 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
**.pyc
|
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from grid_search_tab import create_grid_search_tab
|
| 3 |
+
from theme_config import DashboardTheme
|
| 4 |
+
|
| 5 |
+
def create_dashboard():
|
| 6 |
+
DashboardTheme.setup_matplotlib_style()
|
| 7 |
+
with gr.Blocks(title="Performance Dashboard", theme=DashboardTheme.get_gradio_theme()) as demo:
|
| 8 |
+
with gr.Tabs():
|
| 9 |
+
|
| 10 |
+
with gr.TabItem("Grid search benchmark"):
|
| 11 |
+
create_grid_search_tab()
|
| 12 |
+
|
| 13 |
+
return demo
|
| 14 |
+
|
| 15 |
+
if __name__ == "__main__":
|
| 16 |
+
app = create_dashboard()
|
| 17 |
+
app.launch(server_name="0.0.0.0", server_port=7860)
|
grid_search_tab.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import numpy as np
|
| 4 |
+
from datetime import datetime, timedelta
|
| 5 |
+
from theme_config import DashboardTheme
|
| 6 |
+
|
| 7 |
+
def generate_sales_chart(chart_type, time_period, product_filter, primary_color, secondary_color):
|
| 8 |
+
colors = DashboardTheme.get_chart_colors()
|
| 9 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 10 |
+
|
| 11 |
+
# Generate dummy data based on time period
|
| 12 |
+
if time_period == "Last 7 days":
|
| 13 |
+
days = 7
|
| 14 |
+
elif time_period == "Last 30 days":
|
| 15 |
+
days = 30
|
| 16 |
+
else: # Last 90 days
|
| 17 |
+
days = 90
|
| 18 |
+
|
| 19 |
+
dates = [(datetime.now() - timedelta(days=i)) for i in range(days, 0, -1)]
|
| 20 |
+
|
| 21 |
+
if chart_type == "Revenue":
|
| 22 |
+
# Generate dummy revenue data
|
| 23 |
+
revenue = np.random.randint(1000, 5000, days) + np.sin(np.arange(days)) * 500
|
| 24 |
+
ax.plot(dates, revenue, marker='o', linewidth=2.5, markersize=5, color=primary_color)
|
| 25 |
+
ax.set_ylabel('Revenue ($)')
|
| 26 |
+
ax.set_title(f'Sales Revenue - {product_filter} ({time_period})')
|
| 27 |
+
|
| 28 |
+
elif chart_type == "Units Sold":
|
| 29 |
+
# Generate dummy units data
|
| 30 |
+
units = np.random.randint(50, 200, days) + np.cos(np.arange(days)) * 20
|
| 31 |
+
ax.bar(dates, units, alpha=0.8, color=primary_color, edgecolor=secondary_color, linewidth=0.5)
|
| 32 |
+
ax.set_ylabel('Units Sold')
|
| 33 |
+
ax.set_title(f'Units Sold - {product_filter} ({time_period})')
|
| 34 |
+
|
| 35 |
+
else: # Conversion Rate
|
| 36 |
+
# Generate dummy conversion rate data
|
| 37 |
+
conversion = np.random.uniform(2, 8, days) + np.sin(np.arange(days) * 0.3) * 1
|
| 38 |
+
ax.plot(dates, conversion, marker='s', linewidth=2.5, markersize=5, color=primary_color)
|
| 39 |
+
ax.set_ylabel('Conversion Rate (%)')
|
| 40 |
+
ax.set_title(f'Conversion Rate - {product_filter} ({time_period})')
|
| 41 |
+
|
| 42 |
+
ax.set_xlabel('Date')
|
| 43 |
+
ax.grid(True, alpha=0.3)
|
| 44 |
+
plt.xticks(rotation=45)
|
| 45 |
+
plt.tight_layout()
|
| 46 |
+
|
| 47 |
+
# Apply consistent styling
|
| 48 |
+
ax.spines['top'].set_visible(False)
|
| 49 |
+
ax.spines['right'].set_visible(False)
|
| 50 |
+
ax.tick_params(colors=DashboardTheme.LIGHT_GREY)
|
| 51 |
+
ax.set_facecolor(DashboardTheme.WHITE)
|
| 52 |
+
|
| 53 |
+
return fig
|
| 54 |
+
|
| 55 |
+
def create_grid_search_tab():
|
| 56 |
+
with gr.Row():
|
| 57 |
+
with gr.Column(scale=1):
|
| 58 |
+
gr.Markdown("### Sales Dashboard Options")
|
| 59 |
+
|
| 60 |
+
chart_type = gr.Radio(
|
| 61 |
+
choices=["Revenue", "Units Sold", "Conversion Rate"],
|
| 62 |
+
value="Revenue",
|
| 63 |
+
label="Chart Type"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
time_period = gr.Dropdown(
|
| 67 |
+
choices=["Last 7 days", "Last 30 days", "Last 90 days"],
|
| 68 |
+
value="Last 30 days",
|
| 69 |
+
label="Time Period"
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
product_filter = gr.Dropdown(
|
| 73 |
+
choices=["All Products", "Electronics", "Clothing", "Books", "Home & Garden"],
|
| 74 |
+
value="All Products",
|
| 75 |
+
label="Product Category"
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
region_filter = gr.CheckboxGroup(
|
| 79 |
+
choices=["North America", "Europe", "Asia", "South America"],
|
| 80 |
+
value=["North America", "Europe"],
|
| 81 |
+
label="Regions"
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
gr.Markdown("#### Color Options")
|
| 85 |
+
primary_color = gr.ColorPicker(
|
| 86 |
+
value="#2C3E50",
|
| 87 |
+
label="Primary Color"
|
| 88 |
+
)
|
| 89 |
+
secondary_color = gr.ColorPicker(
|
| 90 |
+
value="#7F8C8D",
|
| 91 |
+
label="Secondary Color"
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
update_btn = gr.Button("Update Chart", variant="primary")
|
| 95 |
+
|
| 96 |
+
with gr.Column(scale=3):
|
| 97 |
+
plot = gr.Plot(label="Sales Analytics")
|
| 98 |
+
|
| 99 |
+
# Update plot when inputs change
|
| 100 |
+
inputs = [chart_type, time_period, product_filter, primary_color, secondary_color]
|
| 101 |
+
|
| 102 |
+
update_btn.click(
|
| 103 |
+
fn=generate_sales_chart,
|
| 104 |
+
inputs=inputs,
|
| 105 |
+
outputs=plot
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
# Initialize with default plot
|
| 109 |
+
chart_type.change(
|
| 110 |
+
fn=generate_sales_chart,
|
| 111 |
+
inputs=inputs,
|
| 112 |
+
outputs=plot
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# Set initial plot
|
| 116 |
+
demo_plot = generate_sales_chart("Revenue", "Last 30 days", "All Products", "#2C3E50", "#7F8C8D")
|
| 117 |
+
plot.value = demo_plot
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import matplotlib as mpl
|
| 4 |
+
|
| 5 |
+
class DashboardTheme:
|
| 6 |
+
# Color palette - Grey, minimalistic, sleek
|
| 7 |
+
PRIMARY_GREY = "#2C3E50" # Dark slate grey
|
| 8 |
+
SECONDARY_GREY = "#34495E" # Medium slate grey
|
| 9 |
+
LIGHT_GREY = "#7F8C8D" # Light grey
|
| 10 |
+
BACKGROUND_GREY = "#ECF0F1" # Very light grey background
|
| 11 |
+
WHITE = "#FFFFFF"
|
| 12 |
+
ACCENT_BLUE = "#3498DB" # Clean blue accent
|
| 13 |
+
SUCCESS_GREEN = "#27AE60" # Clean green
|
| 14 |
+
WARNING_ORANGE = "#F39C12" # Clean orange
|
| 15 |
+
ERROR_RED = "#E74C3C" # Clean red
|
| 16 |
+
|
| 17 |
+
# Chart colors - Professional grey scale with subtle accents
|
| 18 |
+
CHART_COLORS = [
|
| 19 |
+
"#34495E", # Dark grey
|
| 20 |
+
"#5D6D7E", # Medium grey
|
| 21 |
+
"#85929E", # Light grey
|
| 22 |
+
"#3498DB", # Accent blue
|
| 23 |
+
"#27AE60", # Accent green
|
| 24 |
+
"#F39C12", # Accent orange
|
| 25 |
+
"#9B59B6", # Accent purple
|
| 26 |
+
"#E74C3C" # Accent red
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
# Typography
|
| 30 |
+
FONT_FAMILY = "'Inter', 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif"
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def get_gradio_theme():
|
| 34 |
+
"""Create a custom Gradio theme with grey minimalistic design"""
|
| 35 |
+
theme = gr.themes.Soft(
|
| 36 |
+
primary_hue=gr.themes.colors.slate,
|
| 37 |
+
secondary_hue=gr.themes.colors.gray,
|
| 38 |
+
neutral_hue=gr.themes.colors.slate,
|
| 39 |
+
font=gr.themes.GoogleFont("Inter")
|
| 40 |
+
).set(
|
| 41 |
+
# Overall styling
|
| 42 |
+
body_background_fill=DashboardTheme.BACKGROUND_GREY,
|
| 43 |
+
background_fill_primary=DashboardTheme.WHITE,
|
| 44 |
+
background_fill_secondary=DashboardTheme.BACKGROUND_GREY,
|
| 45 |
+
|
| 46 |
+
# Border colors
|
| 47 |
+
border_color_primary=DashboardTheme.LIGHT_GREY,
|
| 48 |
+
border_color_accent=DashboardTheme.ACCENT_BLUE,
|
| 49 |
+
|
| 50 |
+
# Button styling
|
| 51 |
+
button_primary_background_fill=DashboardTheme.PRIMARY_GREY,
|
| 52 |
+
button_primary_background_fill_hover=DashboardTheme.SECONDARY_GREY,
|
| 53 |
+
button_primary_text_color=DashboardTheme.WHITE,
|
| 54 |
+
button_secondary_background_fill=DashboardTheme.WHITE,
|
| 55 |
+
button_secondary_border_color=DashboardTheme.LIGHT_GREY,
|
| 56 |
+
button_secondary_text_color=DashboardTheme.PRIMARY_GREY,
|
| 57 |
+
|
| 58 |
+
# Input styling
|
| 59 |
+
input_background_fill=DashboardTheme.WHITE,
|
| 60 |
+
input_border_color=DashboardTheme.LIGHT_GREY,
|
| 61 |
+
|
| 62 |
+
# Text colors
|
| 63 |
+
body_text_color=DashboardTheme.PRIMARY_GREY,
|
| 64 |
+
body_text_color_subdued=DashboardTheme.LIGHT_GREY,
|
| 65 |
+
|
| 66 |
+
# Panel styling
|
| 67 |
+
panel_background_fill=DashboardTheme.WHITE,
|
| 68 |
+
panel_border_color=DashboardTheme.LIGHT_GREY,
|
| 69 |
+
|
| 70 |
+
# Checkbox/Radio styling
|
| 71 |
+
checkbox_background_color=DashboardTheme.WHITE,
|
| 72 |
+
checkbox_background_color_selected=DashboardTheme.ACCENT_BLUE,
|
| 73 |
+
checkbox_border_color=DashboardTheme.LIGHT_GREY,
|
| 74 |
+
|
| 75 |
+
# Tab styling
|
| 76 |
+
block_title_text_color=DashboardTheme.PRIMARY_GREY,
|
| 77 |
+
block_label_text_color=DashboardTheme.SECONDARY_GREY,
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
return theme
|
| 81 |
+
|
| 82 |
+
@staticmethod
|
| 83 |
+
def setup_matplotlib_style():
|
| 84 |
+
"""Configure matplotlib with the dashboard theme"""
|
| 85 |
+
# Set the style parameters
|
| 86 |
+
plt.style.use('default') # Reset to default first
|
| 87 |
+
|
| 88 |
+
# Configure matplotlib parameters
|
| 89 |
+
mpl.rcParams.update({
|
| 90 |
+
'figure.facecolor': DashboardTheme.WHITE,
|
| 91 |
+
'axes.facecolor': DashboardTheme.WHITE,
|
| 92 |
+
'axes.edgecolor': DashboardTheme.LIGHT_GREY,
|
| 93 |
+
'axes.labelcolor': DashboardTheme.PRIMARY_GREY,
|
| 94 |
+
'axes.axisbelow': True,
|
| 95 |
+
'axes.grid': True,
|
| 96 |
+
'axes.spines.left': True,
|
| 97 |
+
'axes.spines.bottom': True,
|
| 98 |
+
'axes.spines.top': False,
|
| 99 |
+
'axes.spines.right': False,
|
| 100 |
+
'axes.linewidth': 1.0,
|
| 101 |
+
|
| 102 |
+
# Grid styling
|
| 103 |
+
'grid.color': DashboardTheme.LIGHT_GREY,
|
| 104 |
+
'grid.linestyle': '-',
|
| 105 |
+
'grid.linewidth': 0.5,
|
| 106 |
+
'grid.alpha': 0.3,
|
| 107 |
+
|
| 108 |
+
# Text styling
|
| 109 |
+
'text.color': DashboardTheme.PRIMARY_GREY,
|
| 110 |
+
'font.family': 'sans-serif',
|
| 111 |
+
'font.size': 10,
|
| 112 |
+
'axes.titlesize': 12,
|
| 113 |
+
'axes.labelsize': 10,
|
| 114 |
+
'xtick.labelsize': 9,
|
| 115 |
+
'ytick.labelsize': 9,
|
| 116 |
+
'legend.fontsize': 9,
|
| 117 |
+
'axes.titleweight': 'bold',
|
| 118 |
+
|
| 119 |
+
# Tick styling
|
| 120 |
+
'xtick.color': DashboardTheme.LIGHT_GREY,
|
| 121 |
+
'ytick.color': DashboardTheme.LIGHT_GREY,
|
| 122 |
+
'xtick.direction': 'out',
|
| 123 |
+
'ytick.direction': 'out',
|
| 124 |
+
|
| 125 |
+
# Legend styling
|
| 126 |
+
'legend.frameon': True,
|
| 127 |
+
'legend.facecolor': DashboardTheme.WHITE,
|
| 128 |
+
'legend.edgecolor': DashboardTheme.LIGHT_GREY,
|
| 129 |
+
'legend.shadow': False,
|
| 130 |
+
'legend.framealpha': 0.9,
|
| 131 |
+
})
|
| 132 |
+
|
| 133 |
+
@staticmethod
|
| 134 |
+
def get_chart_colors():
|
| 135 |
+
"""Get the standardized chart color palette"""
|
| 136 |
+
return DashboardTheme.CHART_COLORS.copy()
|
| 137 |
+
|
| 138 |
+
@staticmethod
|
| 139 |
+
def get_status_colors():
|
| 140 |
+
"""Get colors for different status indicators"""
|
| 141 |
+
return {
|
| 142 |
+
'success': DashboardTheme.SUCCESS_GREEN,
|
| 143 |
+
'warning': DashboardTheme.WARNING_ORANGE,
|
| 144 |
+
'error': DashboardTheme.ERROR_RED,
|
| 145 |
+
'info': DashboardTheme.ACCENT_BLUE,
|
| 146 |
+
'neutral': DashboardTheme.LIGHT_GREY
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
# Common styling utilities
|
| 150 |
+
def get_section_title_style():
|
| 151 |
+
"""Get consistent styling for section titles"""
|
| 152 |
+
return {
|
| 153 |
+
'color': DashboardTheme.PRIMARY_GREY,
|
| 154 |
+
'font-weight': 'bold',
|
| 155 |
+
'font-size': '1.1em',
|
| 156 |
+
'margin-bottom': '0.5em'
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
def get_metric_card_style():
|
| 160 |
+
"""Get consistent styling for metric cards"""
|
| 161 |
+
return {
|
| 162 |
+
'background': DashboardTheme.WHITE,
|
| 163 |
+
'border': f'1px solid {DashboardTheme.LIGHT_GREY}',
|
| 164 |
+
'border-radius': '8px',
|
| 165 |
+
'padding': '1em',
|
| 166 |
+
'box-shadow': '0 2px 4px rgba(0,0,0,0.05)'
|
| 167 |
+
}
|