Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,13 +2,17 @@ import streamlit as st
|
|
| 2 |
from src.ui.auth import check_authentication
|
| 3 |
from src.ui.pages import dashboard, interaction_logger
|
| 4 |
from src.core.services.interaction_service import InteractionService
|
|
|
|
| 5 |
from src.ai.llm_service import LLMService
|
| 6 |
|
| 7 |
-
# Initialize services
|
| 8 |
def init_services():
|
| 9 |
"""Initialize application services"""
|
| 10 |
if 'services' not in st.session_state:
|
|
|
|
|
|
|
|
|
|
| 11 |
st.session_state.services = {
|
|
|
|
| 12 |
'llm': LLMService(
|
| 13 |
openai_api_key=st.secrets["OPENAI_API_KEY"],
|
| 14 |
anthropic_api_key=st.secrets["ANTHROPIC_API_KEY"]
|
|
@@ -64,7 +68,60 @@ def main():
|
|
| 64 |
dashboard.show()
|
| 65 |
elif page == "Log Interaction":
|
| 66 |
interaction_logger.show()
|
|
|
|
|
|
|
| 67 |
# Add more page routing as needed
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
if __name__ == "__main__":
|
| 70 |
main()
|
|
|
|
| 2 |
from src.ui.auth import check_authentication
|
| 3 |
from src.ui.pages import dashboard, interaction_logger
|
| 4 |
from src.core.services.interaction_service import InteractionService
|
| 5 |
+
from src.core.services.database_service import DatabaseService
|
| 6 |
from src.ai.llm_service import LLMService
|
| 7 |
|
|
|
|
| 8 |
def init_services():
|
| 9 |
"""Initialize application services"""
|
| 10 |
if 'services' not in st.session_state:
|
| 11 |
+
# Initialize database service first
|
| 12 |
+
db_service = DatabaseService()
|
| 13 |
+
|
| 14 |
st.session_state.services = {
|
| 15 |
+
'db': db_service,
|
| 16 |
'llm': LLMService(
|
| 17 |
openai_api_key=st.secrets["OPENAI_API_KEY"],
|
| 18 |
anthropic_api_key=st.secrets["ANTHROPIC_API_KEY"]
|
|
|
|
| 68 |
dashboard.show()
|
| 69 |
elif page == "Log Interaction":
|
| 70 |
interaction_logger.show()
|
| 71 |
+
elif page == "My Accounts":
|
| 72 |
+
show_my_accounts()
|
| 73 |
# Add more page routing as needed
|
| 74 |
|
| 75 |
+
def show_my_accounts():
|
| 76 |
+
"""Display user's accounts page"""
|
| 77 |
+
st.title("My Accounts")
|
| 78 |
+
|
| 79 |
+
# Get user's accounts
|
| 80 |
+
db_service = st.session_state.services['db']
|
| 81 |
+
accounts = db_service.get_user_accounts(st.session_state.user['id'])
|
| 82 |
+
|
| 83 |
+
if not accounts:
|
| 84 |
+
st.info("No accounts found")
|
| 85 |
+
return
|
| 86 |
+
|
| 87 |
+
# Account selection
|
| 88 |
+
selected_account = st.selectbox(
|
| 89 |
+
"Select Account",
|
| 90 |
+
options=accounts,
|
| 91 |
+
format_func=lambda x: x['name']
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
if selected_account:
|
| 95 |
+
# Get account metrics
|
| 96 |
+
metrics = db_service.get_account_metrics(selected_account['id'])
|
| 97 |
+
|
| 98 |
+
# Display metrics
|
| 99 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 100 |
+
with col1:
|
| 101 |
+
st.metric("Total Interactions", metrics['interaction_count'])
|
| 102 |
+
with col2:
|
| 103 |
+
st.metric("Total Contacts", metrics['contact_count'])
|
| 104 |
+
with col3:
|
| 105 |
+
st.metric("Avg Sentiment", f"{metrics['avg_sentiment']:.2f}")
|
| 106 |
+
with col4:
|
| 107 |
+
st.metric("Annual Revenue", f"${selected_account['annual_revenue']}M")
|
| 108 |
+
|
| 109 |
+
# Recent interactions
|
| 110 |
+
st.subheader("Recent Interactions")
|
| 111 |
+
recent = db_service.get_recent_interactions(
|
| 112 |
+
st.session_state.user['id'],
|
| 113 |
+
limit=5
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
for interaction in recent:
|
| 117 |
+
with st.expander(
|
| 118 |
+
f"{interaction['type']} on {interaction['created_at'][:10]}"
|
| 119 |
+
):
|
| 120 |
+
st.write(f"Summary: {interaction['summary']}")
|
| 121 |
+
if interaction['sentiment_score']:
|
| 122 |
+
st.write(f"Sentiment: {interaction['sentiment_score']:.2f}")
|
| 123 |
+
if interaction['metadata'].get('location'):
|
| 124 |
+
st.write(f"Location: {interaction['metadata']['location']}")
|
| 125 |
+
|
| 126 |
if __name__ == "__main__":
|
| 127 |
main()
|