pknayak's picture
Update app.py
79201e4 verified
raw
history blame
3.21 kB
import streamlit as st
st.set_page_config(page_title="CRIS CMS System",layout="wide")
import pandas as pd
import numpy as np
import altair as alt
complaints_count = st.container(border=True) # contains the number of complaints in each bucket
graphs = st.container(border=True) #
dataset = st.container(border=True) #
# TOTAL COUNT SECTION
with complaints_count:
st.header("Complaints counts",divider=True)
data = "./data/complaints_v1.csv"
complaints_df = pd.read_csv(data,sep=",")
total_counts = len(complaints_df.index)
service_issues_counts = complaints_df['sub_cat'].value_counts()['service_issues']
product_issues_counts = complaints_df['sub_cat'].value_counts()['product_issues']
billing_issues_counts = complaints_df['sub_cat'].value_counts()['billing_issues']
col1,col2,col3,col4 = st.columns(4)
col1.metric(label="Total Complaints", value=total_counts, delta="1.2 %")
col2.metric(label="Total Billing Issues", value=service_issues_counts, delta="-1 %")
col3.metric(label="Total Product Issues", value=product_issues_counts, delta="-1.3 %")
col4.metric(label="Total Service Issues ", value=billing_issues_counts, delta="+1.2 ")
#Graphs SECTION
with graphs:
st.header("Complaints plots", divider=True)
col1, col2 = st.columns(2)
with col1:
st.subheader('Complaints mon-o-mon', divider=True)
data = {
'mon_indx': [1,2,3,4,5,6],
'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
'Service Issues': np.random.randint(0, 36, size=6),
'Product Issues': np.random.randint(0, 22, size=6),
'Billing Issues': np.random.randint(0, 19, size=6)
}
# Convert to DataFrame
mom_df = pd.DataFrame(data)
st.line_chart(mom_df,
x='Month',
y=['Service Issues','Product Issues','Billing Issues'],
use_container_width=True)
with col2:
st.subheader('Frequent Issues', divider=True)
issue_labels = ['service_issues', 'product_issues', 'billing_issues']
issue_counts = [complaints_df['sub_cat'].value_counts().get(label, 0) for label in issue_labels]
source = pd.DataFrame({"issue_labels": ['Service Issues', 'Product Issues', 'Billing Issues'], "issue_counts": issue_counts})
chart = alt.Chart(source).mark_arc(innerRadius=120).encode(
theta=alt.Theta(field="issue_counts", type="quantitative"),
color=alt.Color(field="issue_labels", type="nominal"),
)
st.altair_chart(chart, theme="streamlit", use_container_width=True)
# RECENT COMPLAINTS SECTION
with dataset:
st.header("Recent Complaints",divider=True)
ground_truth_data = pd.read_csv("./data/ground_truth.csv")
ground_truth_data.rename(columns= {'audio_id':'Audio ID','file_name':'File Name', 'transcription':'Complaints', 'sub_cat':'Complaint Category'}, inplace = True)
columns = ['Audio ID','File Name', 'Complaints', 'Complaint Category']
st.dataframe(ground_truth_data[columns].iloc[15:23],
hide_index=True,
use_container_width=True
)