import streamlit as st import pandas as pd import os import glob # Load the provider specialty dataset CSV @st.cache_resource def load_specialties(csv_file='Provider-Specialty.csv'): return pd.read_csv(csv_file) specialties = load_specialties() # User interface for specialty selection st.title('Provider Specialty Analyzer') # Dropdown for selecting a specialty specialty_options = specialties['Display Name'].unique() selected_specialty = st.selectbox('Select a Specialty', options=specialty_options) # Display specialties matching the selected option or search keyword search_keyword = st.text_input('Or search for a keyword in specialties') if search_keyword: filtered_specialties = specialties[specialties.apply(lambda row: row.astype(str).str.contains(search_keyword, case=False).any(), axis=1)] else: filtered_specialties = specialties[specialties['Display Name'] == selected_specialty] st.dataframe(filtered_specialties) # Function to find and process text files with two-letter names def process_state_files(specialty_code): files = glob.glob('./*.txt') state_files = [file for file in files if len(os.path.basename(file).split('.')[0]) == 2] results = [] for file in state_files: state_df = pd.read_csv(file, names=['Code', 'Grouping', 'Classification', 'Specialization', 'Definition', 'Notes', 'Display Name', 'Section']) filtered_df = state_df[state_df['Code'] == specialty_code] if not filtered_df.empty: results.append((os.path.basename(file), filtered_df)) return results # Show DataFrame UI for files matching the specialty code in the selected state if st.button('Analyze Text Files for Selected Specialty'): specialty_code = specialties[specialties['Display Name'] == selected_specialty].iloc[0]['Code'] state_data = process_state_files(specialty_code) if state_data: for state, df in state_data: st.subheader(f"Providers in {state} with Specialty '{selected_specialty}':") st.dataframe(df) else: st.write("No matching records found in text files for the selected specialty.")