Update app.py
Browse files
app.py
CHANGED
@@ -3,23 +3,22 @@ import pandas as pd
|
|
3 |
import os
|
4 |
import glob
|
5 |
|
6 |
-
#
|
7 |
@st.cache_resource
|
8 |
def load_specialties(csv_file='Provider-Specialty.csv'):
|
9 |
return pd.read_csv(csv_file)
|
10 |
|
11 |
@st.cache_resource
|
12 |
def find_state_files():
|
13 |
-
# Adjusted to include .csv files specifically for states
|
14 |
return [file for file in glob.glob('./*.csv') if len(os.path.basename(file).split('.')[0]) == 2]
|
15 |
|
16 |
-
# Load the provider specialty dataset
|
17 |
specialties = load_specialties()
|
18 |
|
19 |
# User interface for specialty selection
|
20 |
st.title('Provider Specialty Analyzer π')
|
21 |
|
22 |
-
# Markdown outline with emojis
|
23 |
st.markdown('''
|
24 |
## Specialty Fields Description π
|
25 |
- **Code**: Unique identifier for the specialty π
|
@@ -45,34 +44,34 @@ else:
|
|
45 |
|
46 |
st.dataframe(filtered_specialties)
|
47 |
|
48 |
-
#
|
49 |
-
default_state = 'MN'
|
50 |
state_files = find_state_files()
|
51 |
-
state_options = [os.path.basename(file).split('.')[0] for file in state_files]
|
52 |
-
|
53 |
-
selected_state = st.selectbox('Select a State (optional) πΊοΈ', options=state_options, index=0)
|
54 |
use_specific_state = st.checkbox('Filter by selected state only? β
', value=True)
|
55 |
|
56 |
-
#
|
57 |
-
def process_files(
|
58 |
results = []
|
59 |
-
|
60 |
|
61 |
-
for file in
|
62 |
-
state_df = pd.read_csv(file, header=None) #
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
|
67 |
return results
|
68 |
|
69 |
-
#
|
70 |
if st.button('Analyze Text Files for Selected Specialty π'):
|
71 |
-
|
72 |
-
state_data = process_files(
|
73 |
if state_data:
|
74 |
for state, df in state_data:
|
75 |
-
st.subheader(f"Providers in {state
|
76 |
st.dataframe(df)
|
77 |
else:
|
78 |
st.write("No matching records found in text files for the selected specialty.")
|
|
|
3 |
import os
|
4 |
import glob
|
5 |
|
6 |
+
# Cache the loading of specialties and state files for efficiency
|
7 |
@st.cache_resource
|
8 |
def load_specialties(csv_file='Provider-Specialty.csv'):
|
9 |
return pd.read_csv(csv_file)
|
10 |
|
11 |
@st.cache_resource
|
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 |
+
# Load the provider specialty dataset
|
16 |
specialties = load_specialties()
|
17 |
|
18 |
# User interface for specialty selection
|
19 |
st.title('Provider Specialty Analyzer π')
|
20 |
|
21 |
+
# Markdown outline with emojis for specialty fields
|
22 |
st.markdown('''
|
23 |
## Specialty Fields Description π
|
24 |
- **Code**: Unique identifier for the specialty π
|
|
|
44 |
|
45 |
st.dataframe(filtered_specialties)
|
46 |
|
47 |
+
# State selection UI with MN as the default option for testing
|
|
|
48 |
state_files = find_state_files()
|
49 |
+
state_options = sorted([os.path.basename(file).split('.')[0] for file in state_files])
|
50 |
+
selected_state = st.selectbox('Select a State (optional) πΊοΈ', options=state_options, index=state_options.index('MN') if 'MN' in state_options else 0)
|
|
|
51 |
use_specific_state = st.checkbox('Filter by selected state only? β
', value=True)
|
52 |
|
53 |
+
# Function to process state files and match taxonomy codes
|
54 |
+
def process_files(specialty_codes, specific_state='MN'):
|
55 |
results = []
|
56 |
+
file_to_process = f'./{specific_state}.csv' if use_specific_state else state_files
|
57 |
|
58 |
+
for file in [file_to_process] if use_specific_state else state_files:
|
59 |
+
state_df = pd.read_csv(file, header=None) # Assume no header for simplicity
|
60 |
+
for code in specialty_codes:
|
61 |
+
# Filter rows where the 48th column matches the specialty code
|
62 |
+
filtered_df = state_df[state_df[47] == code]
|
63 |
+
if not filtered_df.empty:
|
64 |
+
results.append((os.path.basename(file).replace('.csv', ''), filtered_df))
|
65 |
|
66 |
return results
|
67 |
|
68 |
+
# Button to initiate analysis
|
69 |
if st.button('Analyze Text Files for Selected Specialty π'):
|
70 |
+
specialty_codes = filtered_specialties['Code'].unique()
|
71 |
+
state_data = process_files(specialty_codes, selected_state if use_specific_state else 'MN')
|
72 |
if state_data:
|
73 |
for state, df in state_data:
|
74 |
+
st.subheader(f"Providers in {state} with Specialty '{selected_specialty}':")
|
75 |
st.dataframe(df)
|
76 |
else:
|
77 |
st.write("No matching records found in text files for the selected specialty.")
|