|
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
|
|
"""
|
|
|
|
df = pd.DataFrame(call_data)
|
|
|
|
|
|
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()
|
|
|
|
|
|
df['sentiment_numeric'] = df['sentiment'].map({'POSITIVE': 1, 'NEGATIVE': -1, 'NEUTRAL': 0})
|
|
|
|
|
|
X = np.array(range(len(df))).reshape(-1, 1)
|
|
y = df['sentiment_numeric'].values
|
|
|
|
model = LinearRegression()
|
|
model.fit(X, y)
|
|
|
|
|
|
trend_score = model.coef_[0]
|
|
trend_interpretation = (
|
|
"Improving" if trend_score > 0.1 else
|
|
"Declining" if trend_score < -0.1 else
|
|
"Stable"
|
|
)
|
|
|
|
|
|
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")
|
|
|
|
|
|
st.write("Insights generation ready.")
|
|
|
|
if __name__ == "__main__":
|
|
main() |