mrradix commited on
Commit
41837f3
Β·
verified Β·
1 Parent(s): 465a970

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -132
app.py CHANGED
@@ -1,144 +1,98 @@
1
- import gradio as gr
 
2
  import os
3
- import json
4
- import datetime
5
- from pathlib import Path
6
 
7
- # Import pages
8
- from pages.dashboard import create_dashboard_page
9
- from pages.tasks import create_tasks_page
10
- from pages.notes import create_notes_page
11
- from pages.goals import create_goals_page
12
- from pages.ai_assistant import create_ai_assistant_page
13
- from pages.search import create_search_page
14
- from pages.analytics import create_analytics_page
15
- from pages.focus import create_focus_page
16
- from pages.integrations_new import create_integrations_page # Using the new integrations page
17
- from pages.settings import create_settings_page
18
- from pages.multimedia import create_multimedia_page
19
 
20
- # Import utilities
21
- from utils.storage import load_data, save_data
22
- from utils.state import initialize_state, record_activity
23
- from utils.config import DATA_DIR, LOGGING_CONFIG
24
- from utils.logging import get_logger
25
- from utils.error_handling import handle_exceptions
26
-
27
- # Initialize logger
28
- logger = get_logger(__name__)
29
-
30
- # Define sidebar items
31
- sidebar_items = [
32
- "🏠 Dashboard",
33
- "πŸ“‹ Tasks & Projects",
34
- "πŸ“ Notes & Docs",
35
- "🎯 Goals & Planning",
36
- "πŸ€– AI Assistant Hub",
37
- "πŸ” Smart Search",
38
- "πŸ“Š Analytics",
39
- "🧘 Focus & Wellness",
40
- "πŸ–ΌοΈ Multimedia",
41
- "πŸ”„ Integrations",
42
- "βš™οΈ Settings"
43
- ]
44
-
45
- # Map sidebar items to page creation functions
46
- page_creators = {
47
- "🏠 Dashboard": create_dashboard_page,
48
- "πŸ“‹ Tasks & Projects": create_tasks_page,
49
- "πŸ“ Notes & Docs": create_notes_page,
50
- "🎯 Goals & Planning": create_goals_page,
51
- "πŸ€– AI Assistant Hub": create_ai_assistant_page,
52
- "πŸ” Smart Search": create_search_page,
53
- "πŸ“Š Analytics": create_analytics_page,
54
- "🧘 Focus & Wellness": create_focus_page,
55
- "πŸ–ΌοΈ Multimedia": create_multimedia_page,
56
- "πŸ”„ Integrations": create_integrations_page,
57
- "βš™οΈ Settings": create_settings_page
58
- }
59
-
60
- @handle_exceptions
61
- def create_app():
62
- """Create and configure the Gradio application"""
63
- logger.info("Initializing Mona application")
64
 
65
- # Initialize application state
66
- state = initialize_state()
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- # Create the Gradio Blocks app
69
- with gr.Blocks(title="Mona - AI Productivity Platform", theme=gr.themes.Soft()) as app:
70
- # Create header
71
- with gr.Row(elem_id="header"):
72
- gr.Markdown("# Mona - AI Productivity Platform")
73
-
74
- # Create main layout with sidebar and content area
75
- with gr.Row():
76
- # Sidebar navigation
77
- with gr.Column(scale=1, elem_id="sidebar"):
78
- # User profile section
79
- with gr.Group(elem_id="user-profile"):
80
- gr.Markdown("### Welcome!")
81
-
82
- # Navigation menu
83
- selected_page = gr.Radio(
84
- choices=sidebar_items,
85
- value=sidebar_items[0],
86
- label="Navigation",
87
- elem_id="nav-menu"
88
- )
89
-
90
- # App info
91
- with gr.Group(elem_id="app-info"):
92
- gr.Markdown("v0.1.0 | Using Free AI Models")
93
-
94
- # Main content area
95
- with gr.Column(scale=4, elem_id="content-area"):
96
- # Create a container for each page
97
- for page_name, create_page in page_creators.items():
98
- with gr.Group(visible=(page_name == sidebar_items[0])) as page_container:
99
- create_page(state)
100
- # Store the container in state for navigation
101
- state[f"{page_name}_container"] = page_container
102
 
103
- # Handle navigation changes
104
- @handle_exceptions
105
- def change_page(page_name):
106
- """Show the selected page and hide others"""
107
- logger.debug(f"Navigating to page: {page_name}")
108
- return [gr.update(visible=(name == page_name)) for name in sidebar_items]
109
 
110
- # Set up navigation event handler
111
- page_containers = [state[f"{name}_container"] for name in sidebar_items]
112
- selected_page.change(change_page, inputs=selected_page, outputs=page_containers)
 
 
 
 
 
 
 
113
 
114
- # Record app usage for analytics
115
- @handle_exceptions
116
- def record_app_usage():
117
- """Record app usage for analytics"""
118
- logger.info("Recording app usage")
119
-
120
- # Record activity using the centralized function
121
- # Commented out due to incorrect parameters
122
- # record_activity requires state, activity_type, and title
123
- # record_activity({
124
- # "type": "app_opened",
125
- # "timestamp": datetime.datetime.now().isoformat()
126
- # })
127
-
128
- # Correct implementation would be:
129
- # record_activity(state, "app_opened", "Application Started")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
- # Record app usage on load
132
- app.load(record_app_usage)
 
 
 
133
 
134
- logger.info("Mona application initialized successfully")
135
- return app
 
 
 
136
 
137
  if __name__ == "__main__":
138
- try:
139
- logger.info("Starting Mona application")
140
- app = create_app()
141
- app.launch()
142
- except Exception as e:
143
- logger.error(f"Failed to start application: {str(e)}")
144
- raise
 
1
+ import streamlit as st
2
+ import sys
3
  import os
 
 
 
4
 
5
+ # Add the current directory to the path
6
+ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 
 
 
 
 
 
 
 
 
 
7
 
8
+ # Import utilities first to test they work
9
+ try:
10
+ from utils.logging import get_logger
11
+ from utils.error_handling import DataError, ValidationError
12
+ from utils.storage import load_data, save_data
13
+
14
+ logger = get_logger(__name__)
15
+ logger.info("All utilities imported successfully")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ except ImportError as e:
18
+ st.error(f"Import error: {e}")
19
+ st.stop()
20
+
21
+ # Now import pages
22
+ try:
23
+ from pages.dashboard import create_dashboard_page
24
+ from pages.tasks import create_tasks_page
25
+ except ImportError as e:
26
+ st.error(f"Pages import error: {e}")
27
+ # Create fallback functions
28
+ def create_dashboard_page():
29
+ st.title("πŸ€– MONA Dashboard")
30
+ st.success("βœ… All utilities loaded successfully!")
31
+ st.info("Dashboard is ready to be implemented")
32
 
33
+ def create_tasks_page():
34
+ st.title("πŸ“‹ MONA Tasks")
35
+ st.success("βœ… All utilities loaded successfully!")
36
+ st.info("Tasks page is ready to be implemented")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
+ # Test data operations
39
+ st.subheader("Testing Data Operations")
 
 
 
 
40
 
41
+ if st.button("Test Save Data"):
42
+ test_data = {"message": "Hello MONA!", "status": "working"}
43
+ try:
44
+ success = save_data(test_data, "test.json", "json")
45
+ if success:
46
+ st.success("Data saved successfully!")
47
+ else:
48
+ st.error("Failed to save data")
49
+ except Exception as e:
50
+ st.error(f"Save error: {e}")
51
 
52
+ if st.button("Test Load Data"):
53
+ try:
54
+ data = load_data("test.json", "json")
55
+ if data:
56
+ st.success("Data loaded successfully!")
57
+ st.json(data)
58
+ else:
59
+ st.warning("No data found")
60
+ except Exception as e:
61
+ st.error(f"Load error: {e}")
62
+
63
+ def main():
64
+ """Main application entry point"""
65
+ st.set_page_config(
66
+ page_title="MONA",
67
+ page_icon="πŸ€–",
68
+ layout="wide",
69
+ initial_sidebar_state="expanded"
70
+ )
71
+
72
+ # Initialize data directory
73
+ from utils.storage import ensure_data_directory
74
+ ensure_data_directory()
75
+
76
+ # Initialize state
77
+ from utils.state import init_session_state
78
+ init_session_state()
79
+
80
+ # Sidebar navigation
81
+ with st.sidebar:
82
+ st.title("πŸ€– MONA")
83
+ st.markdown("---")
84
 
85
+ page = st.radio(
86
+ "Navigation",
87
+ ["Dashboard", "Tasks"],
88
+ index=0
89
+ )
90
 
91
+ # Route to appropriate page
92
+ if page == "Dashboard":
93
+ create_dashboard_page()
94
+ elif page == "Tasks":
95
+ create_tasks_page()
96
 
97
  if __name__ == "__main__":
98
+ main()