Spaces:
Sleeping
Sleeping
| """ | |
| Main Application Module | |
| Integrates all components into a cohesive sales intelligence platform | |
| """ | |
| import streamlit as st | |
| from datetime import datetime | |
| from typing import Dict, Any | |
| from src.ui.auth import check_authentication, authenticate_user # Updated import | |
| from src.core.services.database_service import DatabaseService | |
| from src.core.services.interaction_service import InteractionService | |
| from src.ai.llm_service import LLMService | |
| from src.ui.pages import call_recorder | |
| from src.ui.pages import dashboard, interaction_logger | |
| from src.ui.auth import check_authentication | |
| from src.ui.components.quick_account import show_quick_account_form | |
| from src.ai.services.transcription_service import TranscriptionService | |
| def init_services(): | |
| """Initialize application services""" | |
| if 'services' not in st.session_state: | |
| # Initialize database service first | |
| db_service = DatabaseService() | |
| db_service.generate_synthetic_data() | |
| # Add services to session state | |
| st.session_state.services = { | |
| 'db': db_service, | |
| 'llm': LLMService( | |
| openai_api_key=st.secrets["OPENAI_API_KEY"], | |
| anthropic_api_key=st.secrets["ANTHROPIC_API_KEY"] | |
| ), | |
| 'interaction': InteractionService(), | |
| 'transcription': TranscriptionService( | |
| openai_api_key=st.secrets["OPENAI_API_KEY"] # We can reuse the same OpenAI key | |
| ) | |
| } | |
| def main(): | |
| """Main application entry point""" | |
| st.set_page_config( | |
| page_title="Sales Intelligence Platform", | |
| page_icon="π―", | |
| layout="wide" | |
| ) | |
| # Initialize services | |
| init_services() | |
| # Check authentication | |
| if not check_authentication(): | |
| return | |
| # Sidebar navigation | |
| st.sidebar.title("Navigation") | |
| # Get user role from session | |
| user_role = st.session_state.user.get('role', 'sales_rep') | |
| # Dynamic menu based on user role | |
| menu_options = { | |
| "sales_rep": [ | |
| "π Dashboard", | |
| "π Record Call", # Add this line | |
| "π Log Interaction", | |
| "π₯ My Accounts", | |
| "π Analytics" | |
| ], | |
| "regional_lead": [ | |
| "π Team Dashboard", | |
| "π Performance", | |
| "π Reports" | |
| ], | |
| "head_of_sales": [ | |
| "π Global Dashboard", | |
| "π₯ Team Management", | |
| "π Advanced Analytics" | |
| ] | |
| } | |
| page = st.sidebar.radio( | |
| "Menu", | |
| menu_options.get(user_role, menu_options["sales_rep"]) | |
| ) | |
| # Display user info in sidebar | |
| with st.sidebar: | |
| st.markdown("---") | |
| st.markdown(f"π€ **{st.session_state.user.get('name', 'User')}**") | |
| st.markdown(f"π’ {st.session_state.user.get('company', 'Company')}") | |
| if st.button("Logout"): | |
| del st.session_state.user | |
| st.rerun() | |
| # Route to appropriate page | |
| if page.endswith('Dashboard'): | |
| dashboard.show() | |
| elif page == "π Log Interaction": | |
| interaction_logger.show() | |
| elif page == "π₯ My Accounts": | |
| render_accounts_page() | |
| elif page == "π Analytics": | |
| render_analytics_page() | |
| elif page == "π Record Call": | |
| call_recorder.show() | |
| def render_accounts_page(): | |
| """Render accounts overview page""" | |
| st.title("π₯ My Accounts") | |
| # Get services | |
| db_service = st.session_state.services['db'] | |
| # Get user's accounts | |
| accounts = db_service.get_user_accounts(st.session_state.user['id']) | |
| if not accounts: | |
| st.info("No accounts found") | |
| return | |
| # Account selection | |
| selected_account = st.selectbox( | |
| "Select Account", | |
| options=accounts, | |
| format_func=lambda x: x['name'] | |
| ) | |
| if selected_account: | |
| # Get account metrics | |
| metrics = db_service.get_account_metrics(selected_account['id']) | |
| # Display metrics | |
| col1, col2, col3, col4 = st.columns(4) | |
| with col1: | |
| st.metric("Total Interactions", metrics['interaction_count']) | |
| with col2: | |
| st.metric("Total Contacts", metrics['contact_count']) | |
| with col3: | |
| st.metric("Avg Sentiment", f"{metrics['avg_sentiment']:.2f}") | |
| with col4: | |
| st.metric("Annual Revenue", f"${selected_account['annual_revenue']}M") | |
| def render_analytics_page(): | |
| """Render analytics page""" | |
| st.title("π Analytics") | |
| # Get services | |
| db_service = st.session_state.services['db'] | |
| # Get user's interaction stats | |
| stats = st.session_state.services['interaction'].get_interaction_stats( | |
| db_service, | |
| st.session_state.user['id'] | |
| ) | |
| # Display statistics | |
| st.metric("Total Interactions", stats['total_count']) | |
| st.metric("Average Sentiment", f"{stats['avg_sentiment']:.2f}") | |
| # Show interaction type distribution | |
| st.subheader("Interaction Types") | |
| st.bar_chart(stats['type_distribution']) | |
| if __name__ == "__main__": | |
| main() | |