|
import gradio as gr |
|
import os |
|
import json |
|
import datetime |
|
from pathlib import Path |
|
|
|
|
|
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 |
|
from pages.settings import create_settings_page |
|
from pages.multimedia import create_multimedia_page |
|
|
|
|
|
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 |
|
|
|
|
|
logger = get_logger(__name__) |
|
|
|
|
|
sidebar_items = [ |
|
"π Dashboard", |
|
"π Tasks & Projects", |
|
"π Notes & Docs", |
|
"π― Goals & Planning", |
|
"π€ AI Assistant Hub", |
|
"π Smart Search", |
|
"π Analytics", |
|
"π§ Focus & Wellness", |
|
"πΌοΈ Multimedia", |
|
"π Integrations", |
|
"βοΈ Settings" |
|
] |
|
|
|
|
|
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") |
|
|
|
|
|
state = initialize_state() |
|
|
|
|
|
with gr.Blocks(title="Mona - AI Productivity Platform", theme=gr.themes.Soft()) as app: |
|
|
|
with gr.Row(elem_id="header"): |
|
gr.Markdown("# Mona - AI Productivity Platform") |
|
|
|
|
|
with gr.Row(): |
|
|
|
with gr.Column(scale=1, elem_id="sidebar"): |
|
|
|
with gr.Group(elem_id="user-profile"): |
|
gr.Markdown("### Welcome!") |
|
|
|
|
|
selected_page = gr.Radio( |
|
choices=sidebar_items, |
|
value=sidebar_items[0], |
|
label="Navigation", |
|
elem_id="nav-menu" |
|
) |
|
|
|
|
|
with gr.Group(elem_id="app-info"): |
|
gr.Markdown("v0.1.0 | Using Free AI Models") |
|
|
|
|
|
with gr.Column(scale=4, elem_id="content-area"): |
|
|
|
for page_name, create_page in page_creators.items(): |
|
with gr.Group(visible=(page_name == sidebar_items[0])) as page_container: |
|
create_page(state) |
|
|
|
state[f"{page_name}_container"] = page_container |
|
|
|
|
|
@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] |
|
|
|
|
|
page_containers = [state[f"{name}_container"] for name in sidebar_items] |
|
selected_page.change(change_page, inputs=selected_page, outputs=page_containers) |
|
|
|
|
|
@handle_exceptions |
|
def record_app_usage(): |
|
"""Record app usage for analytics""" |
|
logger.info("Recording app usage") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |