import streamlit as st
import pandas as pd
import time
#from st_aggrid import AgGrid
# Set page layout
st.set_page_config(layout="wide", page_title="Test Cases Prediction App")
# Initialize session state for active tab, progress, and file upload
if 'active_tab' not in st.session_state:
st.session_state.active_tab = None#'๐ Load CSV'
if 'progress' not in st.session_state:
st.session_state.progress = 0
if 'file_uploaded' not in st.session_state:
st.session_state.file_uploaded = False
if 'predict_done' not in st.session_state:
st.session_state.predict_done = False
if "prediction_results_shown" not in st.session_state:
st.session_state.prediction_results_shown = False
if "deploy_done" not in st.session_state:
st.session_state.deploy_done = False
# Define tab styles
tab_styles = {
'Load Input File': 'black',
'Predict': 'black',
'Prediction Results': 'black',
'Deploy': 'black'
}
# Update active tab style
if st.session_state.active_tab:
tab_styles[st.session_state.active_tab] = 'blue'
# Create a sidebar for buttons
with st.sidebar:
st.image(r"Logo.jpg", width=None)
if st.button('๐ Load Deployment details', use_container_width=True):
st.session_state.active_tab = 'Load Input File'
#st.session_state.progress = 25
st.rerun()
if st.button('๐ Predict', use_container_width=True, disabled=not st.session_state.file_uploaded):
st.session_state.active_tab = 'Predict'
st.session_state.progress = 50
st.rerun()
if st.button('๐กPrediction Results', use_container_width=True, disabled=not st.session_state.predict_done):
st.session_state.active_tab = 'Prediction Results'
st.session_state.progress = 75
st.rerun()
if st.button('๐ Deploy', use_container_width=True, disabled=not st.session_state.prediction_results_shown):
st.session_state.active_tab = 'Deploy'
st.session_state.deploy_done = True
st.session_state.progress = 100
st.rerun()
# Create tabs aligned horizontally on the upper side
# Main content area (70% width)
# with open(r"C:\Users\SKumar28\Desktop\QA_AI_streamlit\ST_APP\assests\styles.css") as f:
# st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
with st.container():
# st.markdown(f"### <span style='color:{tab_styles['Predict']};background-color: #2471a3'>", unsafe_allow_html=True)
st.title("Application Test Plan AI Framework")
# background_color = "lightblue"
# Load the CSS file
# with open(r"C:\Users\SKumar28\Desktop\QA_AI_streamlit\ST_APP\assests\styles.css") as f:
# st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
tab1, tab2, tab3, tab4 = st.columns(4)
with tab1:
st.markdown(f"### <span style='color:{tab_styles['Load Input File']}; font-size: 24px; height: 13vh; border-radius: 10px; text-align: center'>Load Input File </span>", unsafe_allow_html=True)
#st.markdown('<div class="column">๐Load Deployment details</div>', unsafe_allow_html=True)
#st.markdown(f"""<style> .st-column {background-color: {background_color}; } </style> """, unsafe_allow_html=True)
with tab2:
st.markdown(f"### <span style='color:{tab_styles['Predict']};b font-size: 24px; height: 13vh; text-align: center'>Predict</span>", unsafe_allow_html=True)
#st.markdown('<div class="column">๐ค Predict</div>', unsafe_allow_html=True)
with tab3:
st.markdown(f"### <span style='color:{tab_styles['Prediction Results']}; font-size: 24px; height: 13vh; text-align: center'>Prediction Results</span>", unsafe_allow_html=True)
with tab4:
st.markdown(f"### <span style='color:{tab_styles['Deploy']}; font-size: 24px; height: 13vh; text-align: center'>Deploy</span>", unsafe_allow_html=True)
# Display progress bar
progress_bar = st.progress(st.session_state.progress)
# Function to load CSV and show summary
# def load_csv():
# uploaded_file = st.file_uploader("Browse input file for prediction", type=["csv"])
# if uploaded_file is not None:
# df = pd.read_csv(uploaded_file)
# df_grouped= df.groupby('Feature').agg({'File Changed': ['sum','count']})
# df_grouped.columns = ['File Changed Count', 'File Count']
# df_grouped= df_grouped.reset_index()
# st.write("Code File changes summary:")
# st.dataframe(df_grouped, hide_index=True)
# # Mark file as uploaded and enable Predict button
# st.session_state.file_uploaded = True
# st.session_state.progress = 25
# Blank screen until an action is performed
if not st.session_state.active_tab:
st.write("๐น **Click an option from the left navigation to begin.**")
# Display content based on active tab
elif st.session_state.active_tab == 'Load Input File':
# load_csv()
uploaded_file = st.file_uploader("Browse input file for prediction", type=["csv"])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
st.session_state.file_uploaded = True
df_grouped= df.groupby('Feature').agg({'File Changed': ['sum','count']})
df_grouped.columns = ['File Changed Count', 'File Count']
df_grouped= df_grouped.reset_index()
st.write("Code File changes summary:")
st.dataframe(df_grouped, hide_index=True, use_container_width=True)#, width=600, height=300)
#AgGrid(df_grouped)
# Mark file as uploaded and enable Predict button
st.session_state.file_uploaded = True
st.session_state.progress = 25
# st.session_state.progress = 25
elif st.session_state.active_tab == 'Predict':
# prediction_summary = predict()
# st.write(prediction_summary)
if st.session_state.file_uploaded:# is not None:
# st.session_state.csv_uploaded = None
model_list= ['MLP', 'Reinforcement MLP']
#st.header("Select the model")
model_select= st.selectbox("Select the model for prediction", options= model_list)
with st.spinner("Running predictions..."):
time.sleep(2) # Simulating processing time
df = pd.read_csv("https://py.cafe/files/surajbhu/streamlit_TC/TestCasePrediction.csv")
st.session_state.df_predictions = df
st.session_state.predict_done = True
st.success("โ
Prediction complete!")
threshold_value = st.slider("Decision Threshold", min_value=0.00, max_value=1.00, value=0.52)
col1, col2 = st.columns(2)
# Display image in the first column
with col1:
st.image("https://py.cafe/files/surajbhu/streamlit_TC/Threshold.png", width=400)
# Display dataframe in the second column
with col2:
df['Risky/Non Risky'] = df.apply(lambda row: 0 if row['Prob'] < threshold_value else 1, axis=1)
prediction= df.groupby('Feature').agg({'Risky/Non Risky': ['sum','count']})
prediction.columns = ['Risky Test Cases Count', 'Total Test Cases Count']
prediction= prediction.reset_index()
st.write(threshold_value)
st.dataframe(prediction, hide_index=True, use_container_width=True)
elif st.session_state.active_tab == 'Prediction Results':
if st.session_state.predict_done:
pred_count = st.session_state.df_predictions["Risky/Non Risky Prediction"].value_counts()
pred_count.columns = ['Count']
pred_count= pred_count.reset_index()
percentages = st.session_state.df_predictions["Risky/Non Risky Prediction"].value_counts(normalize=True) * 100
percentages = percentages.reset_index()
percentages.columns = ['Risky/Non Risky Prediction','Percentage']
pred_summary= pd.merge(pred_count, percentages, on= 'Risky/Non Risky Prediction')
st.write("### Prediction Summary")
st.dataframe(pred_summary, hide_index=True, use_container_width=True)
st.write("### Risky Test Cases by feature")
CF= pd.read_csv("https://py.cafe/files/surajbhu/streamlit_TC/CF.csv")
CF_summary= CF.groupby('Feature').agg({'File Changed': ['sum','count']})
CF_summary.columns = [ 'Changed CF Count', 'Total CF Count']
CF_summary= CF_summary.reset_index()
pred_data= st.session_state.df_predictions.groupby('Feature').agg({'Risky/Non Risky Prediction': ['sum','count']})
pred_data.columns = ['Risky Test Cases Count', 'Total Test Cases Count']
pred_data= pred_data.reset_index()
summarydata= pd.merge(CF_summary,pred_data, on= 'Feature')
st.dataframe(summarydata, hide_index=True, use_container_width=True)
# Download predictions
st.download_button(
label="๐ฅ Download Predictions",
data=st.session_state.df_predictions.to_csv(index=False),
file_name="predictions_output.csv",
mime="text/csv"
)
st.session_state.prediction_results_shown=True
# prediction_results_summary = show_prediction_results()
# st.write(prediction_results_summary)
elif st.session_state.active_tab == 'Deploy':
if st.session_state.prediction_results_shown:
st.write("โ
**Test cases deployed for testing.**")
df_prediction = pd.read_csv("https://py.cafe/files/surajbhu/streamlit_TC/TestCasePrediction.csv")
Risky_Testcase= df_prediction[df_prediction['Risky/Non Risky Prediction']==1]
st.dataframe(Risky_Testcase, hide_index=True, use_container_width=True, height=500)