File size: 1,610 Bytes
a616221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.linear_model import LinearRegression
import streamlit as st

def generate_insights(call_data):
    """

    Generate ML insights and visualizations from call data

    """
    # Convert call data to DataFrame
    df = pd.DataFrame(call_data)
    
    # Sentiment distribution pie chart
    plt.figure(figsize=(10, 6))
    sentiment_counts = df['sentiment'].value_counts()
    plt.pie(sentiment_counts, labels=sentiment_counts.index, autopct='%1.1f%%')
    plt.title('Sentiment Distribution')
    st.pyplot(plt)
    plt.close()

    # Calculate sentiment trend
    df['sentiment_numeric'] = df['sentiment'].map({'POSITIVE': 1, 'NEGATIVE': -1, 'NEUTRAL': 0})
    
    # Simple trend analysis
    X = np.array(range(len(df))).reshape(-1, 1)
    y = df['sentiment_numeric'].values
    
    model = LinearRegression()
    model.fit(X, y)
    
    # Predict trend
    trend_score = model.coef_[0]
    trend_interpretation = (
        "Improving" if trend_score > 0.1 else 
        "Declining" if trend_score < -0.1 else 
        "Stable"
    )
    
    # Summary metrics
    st.subheader("Call Analysis Summary")
    st.write(f"Total Calls: {len(df)}")
    st.write("Sentiment Breakdown:")
    st.write(sentiment_counts)
    st.write(f"Sentiment Trend: {trend_interpretation}")

def main():
    st.title("Sales Call Insights")
    
    # Placeholder for loading data mechanism
    st.write("Insights generation ready.")

if __name__ == "__main__":
    main()