Update app.py
Browse files
app.py
CHANGED
@@ -3,19 +3,20 @@ import pandas as pd
|
|
3 |
import os
|
4 |
import glob
|
5 |
|
6 |
-
# Cache the loading of specialties
|
7 |
-
@st.
|
8 |
def load_specialties(csv_file='Provider-Specialty.csv'):
|
9 |
return pd.read_csv(csv_file)
|
10 |
|
11 |
-
|
|
|
12 |
def find_state_files():
|
13 |
return [file for file in glob.glob('./*.csv') if len(os.path.basename(file).split('.')[0]) == 2]
|
14 |
|
15 |
specialties = load_specialties()
|
16 |
|
17 |
-
# UI for specialty selection
|
18 |
-
st.title('Provider Specialty Analyzer π')
|
19 |
|
20 |
st.markdown('''
|
21 |
## Specialty Fields Description π
|
@@ -29,9 +30,11 @@ st.markdown('''
|
|
29 |
- **Section**: Indicates the section of healthcare it belongs to π
|
30 |
''')
|
31 |
|
|
|
32 |
specialty_options = specialties['Display Name'].unique()
|
33 |
selected_specialty = st.selectbox('Select a Specialty π©Ί', options=specialty_options)
|
34 |
|
|
|
35 |
search_keyword = st.text_input('Or search for a keyword in specialties π')
|
36 |
if search_keyword:
|
37 |
filtered_specialties = specialties[specialties.apply(lambda row: row.astype(str).str.contains(search_keyword, case=False).any(), axis=1)]
|
@@ -40,31 +43,34 @@ else:
|
|
40 |
|
41 |
st.dataframe(filtered_specialties)
|
42 |
|
43 |
-
# State selection with
|
44 |
state_files = find_state_files()
|
45 |
state_options = sorted([os.path.basename(file).split('.')[0] for file in state_files])
|
46 |
selected_state = st.selectbox('Select a State (optional) πΊοΈ', options=state_options, index=state_options.index('MN') if 'MN' in state_options else 0)
|
|
|
|
|
47 |
use_specific_state = st.checkbox('Filter by selected state only? β
', value=True)
|
48 |
|
|
|
49 |
def process_files(specialty_codes, specific_state='MN'):
|
50 |
results = []
|
51 |
file_to_process = f'./{specific_state}.csv' if use_specific_state else state_files
|
52 |
|
53 |
for file in [file_to_process] if use_specific_state else state_files:
|
54 |
state_df = pd.read_csv(file, header=None) # Assuming no header for simplicity
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
results.append((os.path.basename(file).replace('.csv', ''), filtered_df))
|
59 |
|
60 |
return results
|
61 |
|
|
|
62 |
if st.button('Analyze Text Files for Selected Specialty π'):
|
63 |
specialty_codes = filtered_specialties['Code'].tolist()
|
64 |
-
state_data = process_files(specialty_codes, selected_state if use_specific_state else
|
65 |
if state_data:
|
66 |
for state, df in state_data:
|
67 |
-
st.subheader(f"Providers in {state} with Specialties related to '{search_keyword}':")
|
68 |
st.dataframe(df)
|
69 |
else:
|
70 |
st.write("No matching records found in text files for the selected specialties.")
|
|
|
3 |
import os
|
4 |
import glob
|
5 |
|
6 |
+
# Cache the loading of specialties for efficiency
|
7 |
+
@st.cache(allow_output_mutation=True)
|
8 |
def load_specialties(csv_file='Provider-Specialty.csv'):
|
9 |
return pd.read_csv(csv_file)
|
10 |
|
11 |
+
# Cache the finding of state files to avoid repeated file system access
|
12 |
+
@st.cache(allow_output_mutation=True)
|
13 |
def find_state_files():
|
14 |
return [file for file in glob.glob('./*.csv') if len(os.path.basename(file).split('.')[0]) == 2]
|
15 |
|
16 |
specialties = load_specialties()
|
17 |
|
18 |
+
# UI for specialty selection with an engaging title
|
19 |
+
st.title('Provider Specialty Analyzer with Code Grouping and Classification π')
|
20 |
|
21 |
st.markdown('''
|
22 |
## Specialty Fields Description π
|
|
|
30 |
- **Section**: Indicates the section of healthcare it belongs to π
|
31 |
''')
|
32 |
|
33 |
+
# Allows users to select or search for a specialty
|
34 |
specialty_options = specialties['Display Name'].unique()
|
35 |
selected_specialty = st.selectbox('Select a Specialty π©Ί', options=specialty_options)
|
36 |
|
37 |
+
# Keyword search functionality
|
38 |
search_keyword = st.text_input('Or search for a keyword in specialties π')
|
39 |
if search_keyword:
|
40 |
filtered_specialties = specialties[specialties.apply(lambda row: row.astype(str).str.contains(search_keyword, case=False).any(), axis=1)]
|
|
|
43 |
|
44 |
st.dataframe(filtered_specialties)
|
45 |
|
46 |
+
# State selection UI with default selection for testing
|
47 |
state_files = find_state_files()
|
48 |
state_options = sorted([os.path.basename(file).split('.')[0] for file in state_files])
|
49 |
selected_state = st.selectbox('Select a State (optional) πΊοΈ', options=state_options, index=state_options.index('MN') if 'MN' in state_options else 0)
|
50 |
+
|
51 |
+
# Checkbox to filter by selected state only
|
52 |
use_specific_state = st.checkbox('Filter by selected state only? β
', value=True)
|
53 |
|
54 |
+
# Process files based on specialty codes and state selection
|
55 |
def process_files(specialty_codes, specific_state='MN'):
|
56 |
results = []
|
57 |
file_to_process = f'./{specific_state}.csv' if use_specific_state else state_files
|
58 |
|
59 |
for file in [file_to_process] if use_specific_state else state_files:
|
60 |
state_df = pd.read_csv(file, header=None) # Assuming no header for simplicity
|
61 |
+
filtered_df = state_df[state_df[47].isin(specialty_codes)] # Assuming the code is in the 48th column
|
62 |
+
if not filtered_df.empty:
|
63 |
+
results.append((os.path.basename(file).replace('.csv', ''), filtered_df))
|
|
|
64 |
|
65 |
return results
|
66 |
|
67 |
+
# Button to initiate the analysis
|
68 |
if st.button('Analyze Text Files for Selected Specialty π'):
|
69 |
specialty_codes = filtered_specialties['Code'].tolist()
|
70 |
+
state_data = process_files(specialty_codes, selected_state if use_specific_state else None)
|
71 |
if state_data:
|
72 |
for state, df in state_data:
|
73 |
+
st.subheader(f"Providers in {state} with Specialties related to '{search_keyword or selected_specialty}':")
|
74 |
st.dataframe(df)
|
75 |
else:
|
76 |
st.write("No matching records found in text files for the selected specialties.")
|