awacke1 commited on
Commit
3d956aa
Β·
verified Β·
1 Parent(s): 58bcf0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -14
app.py CHANGED
@@ -12,13 +12,11 @@ def load_specialties(csv_file='Provider-Specialty.csv'):
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 πŸ†”
@@ -31,11 +29,9 @@ st.markdown('''
31
  - **Section**: Indicates the section of healthcare it belongs to πŸ“š
32
  ''')
33
 
34
- # Dropdown for selecting a specialty
35
  specialty_options = specialties['Display Name'].unique()
36
  selected_specialty = st.selectbox('Select a Specialty 🩺', options=specialty_options)
37
 
38
- # Display specialties matching the selected option or search keyword
39
  search_keyword = st.text_input('Or search for a keyword in specialties πŸ”')
40
  if search_keyword:
41
  filtered_specialties = specialties[specialties.apply(lambda row: row.astype(str).str.contains(search_keyword, case=False).any(), axis=1)]
@@ -44,34 +40,31 @@ else:
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.")
 
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 πŸ“
22
  - **Code**: Unique identifier for the specialty πŸ†”
 
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
 
41
  st.dataframe(filtered_specialties)
42
 
43
+ # State selection with MN as default for testing
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
  for code in specialty_codes:
56
+ filtered_df = state_df[state_df[47].isin(specialty_codes)] # Match against 48th column
 
57
  if not filtered_df.empty:
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 'MN')
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.")