i want to create a a stream lit ui wiche have a nav bar this navbar contain 4 section name them by your own creation in each section i want to upload a file and when i upload it i want to show a quality check about columns name columns type and if the qualiy passed succefuly i want to show a message in which i ask if user are sure to upload this file and when upload a bad file this will impact the behavior of segmentation and if the client press yes show a message of sucecfully uplaoded
Drop files here
or click to upload
import streamlit as st
import pandas as pd
st.title('File Upload Quality Check')
# Navigation
nav_options = ['Section 1', 'Section 2', 'Section 3', 'Section 4']
selected_section = st.sidebar.selectbox('Select a section', nav_options)
# Function to perform quality check on the uploaded file
def quality_check(uploaded_file):
data = pd.read_excel(uploaded_file)
column_names = data.columns.tolist()
column_types = data.dtypes.to_dict()
# Check for specific qualities
departments = {'department1': 'Number', 'department2': 'String'}
quality_passed = True
quality_messages = []
for col in departments:
if col not in column_names:
quality_passed = False
quality_messages.append(f'Column {col} is missing.')
continue
if str(column_types[col]) != departments[col]:
quality_passed = False
quality_messages.append(f'Column {col} type is incorrect. Expected {departments[col]}, got {column_types[col]}')
return quality_passed, quality_messages
# Section logic
if selected_section:
uploaded_file = st.file_uploader(f'Upload your file for {selected_section}', type='csv')
if uploaded_file is not None:
quality_passed, messages = quality_check(uploaded_file)
if quality_passed:
st.success('Quality check passed!')
if st.button('Are you sure you want to upload this file?'):
st.success('File successfully uploaded!')
else:
st.error('Quality check failed!')
st.write('\n'.join(messages))
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?