Py.Cafe

surajbhu/

streamlit_TC

Customizable Progress Bar and Container Example

DocsPricing
  • assests/
  • CF.csv
  • Logo.jpg
  • TestCasePrediction.csv
  • Threshold.png
  • app.py
  • requirements.txt
app.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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)