File size: 5,125 Bytes
fa537fa
 
 
 
74710c3
fa537fa
 
 
3863768
629a646
 
 
ed99398
e9afb19
76ab2d4
84f780e
c3e640f
f891957
74710c3
f510616
76ab2d4
629a646
 
 
 
 
8c4b9a4
fa537fa
629a646
 
 
 
 
 
 
c3e640f
 
 
 
fa537fa
 
74710c3
b441384
37325ff
fa537fa
37325ff
 
 
 
90e4f6b
b441384
74710c3
b441384
 
 
74710c3
b441384
 
74710c3
b441384
 
74710c3
b441384
 
fa537fa
 
f891957
fa537fa
 
 
 
 
 
 
 
 
 
 
 
 
 
b441384
37325ff
fa537fa
b441384
 
 
 
 
 
 
 
 
37325ff
b441384
 
c4722f7
b441384
 
fa537fa
629a646
fa537fa
629a646
fa537fa
 
 
 
f891957
 
74710c3
fa537fa
 
 
38a2b30
fa537fa
38a2b30
fa537fa
 
38a2b30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa537fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38a2b30
74710c3
9ad0c18
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"""
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()