Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
import glob
|
5 |
+
|
6 |
+
# Load the provider specialty dataset CSV
|
7 |
+
@st.cache
|
8 |
+
def load_specialties(csv_file='specialty_dataset.csv'):
|
9 |
+
return pd.read_csv(csv_file)
|
10 |
+
|
11 |
+
specialties = load_specialties()
|
12 |
+
|
13 |
+
# User interface for specialty selection
|
14 |
+
st.title('Provider Specialty Analyzer')
|
15 |
+
|
16 |
+
# Dropdown for selecting a specialty
|
17 |
+
specialty_options = specialties['Display Name'].unique()
|
18 |
+
selected_specialty = st.selectbox('Select a Specialty', options=specialty_options)
|
19 |
+
|
20 |
+
# Display specialties matching the selected option or search keyword
|
21 |
+
search_keyword = st.text_input('Or search for a keyword in specialties')
|
22 |
+
if search_keyword:
|
23 |
+
filtered_specialties = specialties[specialties.apply(lambda row: row.astype(str).str.contains(search_keyword, case=False).any(), axis=1)]
|
24 |
+
else:
|
25 |
+
filtered_specialties = specialties[specialties['Display Name'] == selected_specialty]
|
26 |
+
|
27 |
+
st.dataframe(filtered_specialties)
|
28 |
+
|
29 |
+
# Function to find and process text files with two-letter names
|
30 |
+
def process_state_files(specialty_code):
|
31 |
+
files = glob.glob('./*.txt')
|
32 |
+
state_files = [file for file in files if len(os.path.basename(file).split('.')[0]) == 2]
|
33 |
+
results = []
|
34 |
+
|
35 |
+
for file in state_files:
|
36 |
+
state_df = pd.read_csv(file, names=['Code', 'Grouping', 'Classification', 'Specialization', 'Definition', 'Notes', 'Display Name', 'Section'])
|
37 |
+
filtered_df = state_df[state_df['Code'] == specialty_code]
|
38 |
+
if not filtered_df.empty:
|
39 |
+
results.append((os.path.basename(file), filtered_df))
|
40 |
+
|
41 |
+
return results
|
42 |
+
|
43 |
+
# Show DataFrame UI for files matching the specialty code in the selected state
|
44 |
+
if st.button('Analyze Text Files for Selected Specialty'):
|
45 |
+
specialty_code = specialties[specialties['Display Name'] == selected_specialty].iloc[0]['Code']
|
46 |
+
state_data = process_state_files(specialty_code)
|
47 |
+
if state_data:
|
48 |
+
for state, df in state_data:
|
49 |
+
st.subheader(f"Providers in {state} with Specialty '{selected_specialty}':")
|
50 |
+
st.dataframe(df)
|
51 |
+
else:
|
52 |
+
st.write("No matching records found in text files for the selected specialty.")
|
53 |
+
|