File size: 5,249 Bytes
8e4018d 8f6c270 8e4018d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
import gradio as gr
import os
import json
import datetime
from pathlib import Path
# Import pages
from pages.dashboard import create_dashboard_page
from pages.tasks import create_tasks_page
from pages.notes import create_notes_page
from pages.goals import create_goals_page
from pages.ai_assistant import create_ai_assistant_page
from pages.search import create_search_page
from pages.analytics import create_analytics_page
from pages.focus import create_focus_page
from pages.integrations_new import create_integrations_page # Using the new integrations page
from pages.settings import create_settings_page
from pages.multimedia import create_multimedia_page
# Import utilities
from utils.storage import load_data, save_data
from utils.state import initialize_state, record_activity
from utils.config import DATA_DIR, LOGGING_CONFIG
from utils.logging import get_logger
from utils.error_handling import handle_exceptions
# Initialize logger
logger = get_logger(__name__)
# Define sidebar items
sidebar_items = [
"π Dashboard",
"π Tasks & Projects",
"π Notes & Docs",
"π― Goals & Planning",
"π€ AI Assistant Hub",
"π Smart Search",
"π Analytics",
"π§ Focus & Wellness",
"πΌοΈ Multimedia",
"π Integrations",
"βοΈ Settings"
]
# Map sidebar items to page creation functions
page_creators = {
"π Dashboard": create_dashboard_page,
"π Tasks & Projects": create_tasks_page,
"π Notes & Docs": create_notes_page,
"π― Goals & Planning": create_goals_page,
"π€ AI Assistant Hub": create_ai_assistant_page,
"π Smart Search": create_search_page,
"π Analytics": create_analytics_page,
"π§ Focus & Wellness": create_focus_page,
"πΌοΈ Multimedia": create_multimedia_page,
"π Integrations": create_integrations_page,
"βοΈ Settings": create_settings_page
}
@handle_exceptions
def create_app():
"""Create and configure the Gradio application"""
logger.info("Initializing Mona application")
# Initialize application state
state = initialize_state()
# Create the Gradio Blocks app
with gr.Blocks(title="Mona - AI Productivity Platform", theme=gr.themes.Soft()) as app:
# Create header
with gr.Row(elem_id="header"):
gr.Markdown("# Mona - AI Productivity Platform")
# Create main layout with sidebar and content area
with gr.Row():
# Sidebar navigation
with gr.Column(scale=1, elem_id="sidebar"):
# User profile section
with gr.Group(elem_id="user-profile"):
gr.Markdown("### Welcome!")
# Navigation menu
selected_page = gr.Radio(
choices=sidebar_items,
value=sidebar_items[0],
label="Navigation",
elem_id="nav-menu"
)
# App info
with gr.Group(elem_id="app-info"):
gr.Markdown("v0.1.0 | Using Free AI Models")
# Main content area
with gr.Column(scale=4, elem_id="content-area"):
# Create a container for each page
for page_name, create_page in page_creators.items():
with gr.Group(visible=(page_name == sidebar_items[0])) as page_container:
create_page(state)
# Store the container in state for navigation
state[f"{page_name}_container"] = page_container
# Handle navigation changes
@handle_exceptions
def change_page(page_name):
"""Show the selected page and hide others"""
logger.debug(f"Navigating to page: {page_name}")
return [gr.update(visible=(name == page_name)) for name in sidebar_items]
# Set up navigation event handler
page_containers = [state[f"{name}_container"] for name in sidebar_items]
selected_page.change(change_page, inputs=selected_page, outputs=page_containers)
# Record app usage for analytics
@handle_exceptions
def record_app_usage():
"""Record app usage for analytics"""
logger.info("Recording app usage")
# Record activity using the centralized function
# Commented out due to incorrect parameters
# record_activity requires state, activity_type, and title
# record_activity({
# "type": "app_opened",
# "timestamp": datetime.datetime.now().isoformat()
# })
# Correct implementation would be:
# record_activity(state, "app_opened", "Application Started")
# Record app usage on load
app.load(record_app_usage)
logger.info("Mona application initialized successfully")
return app
if __name__ == "__main__":
try:
logger.info("Starting Mona application")
app = create_app()
app.launch()
except Exception as e:
logger.error(f"Failed to start application: {str(e)}")
raise |