sanjayw commited on
Commit
63ec242
·
1 Parent(s): 6cc4acf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -37
app.py CHANGED
@@ -1,43 +1,46 @@
1
  import streamlit as st
 
2
  import pandas as pd
3
- import plotly.graph_objects as go
4
- from transformers import pipeline
5
-
6
- # Define the Hugging Face model pipeline
7
- nlp = pipeline("sentiment-analysis")
8
-
9
- # Define a Python list dictionary of the top five largest hospitals in Minnesota
10
- hospital_data = [
11
- {'name': 'Mayo Clinic Hospital - Rochester', 'beds': 2147, 'latitude': 44.022, 'longitude': -92.466},
12
- {'name': 'St. Cloud Hospital', 'beds': 489, 'latitude': 45.570, 'longitude': -94.173},
13
- {'name': 'Abbott Northwestern Hospital', 'beds': 632, 'latitude': 44.952, 'longitude': -93.262},
14
- {'name': 'Mercy Hospital - Coon Rapids', 'beds': 426, 'latitude': 45.157, 'longitude': -93.316},
15
- {'name': 'United Hospital', 'beds': 460, 'latitude': 44.941, 'longitude': -93.105},
 
16
  ]
17
 
18
- # Convert the hospital data to a Pandas DataFrame and save it as a CSV file
19
- hospital_df = pd.DataFrame(hospital_data)
20
- hospital_df.to_csv('hospital_data.csv', index=False)
21
 
22
  # Define the Streamlit app
23
- st.title('Minnesota Hospital Data')
24
-
25
- # Display the hospital data as a table
26
- st.write(hospital_df)
27
-
28
- # Analyze the hospital names using the Hugging Face model
29
- sentiments = nlp([h['name'] for h in hospital_data])
30
-
31
- # Create a dictionary of hospital names and their sentiment scores
32
- sentiment_scores = {h['name']: s['score'] for h, s in zip(hospital_data, sentiments)}
33
-
34
- # Create a Plotly treemap of hospital beds by name and sentiment score
35
- fig = go.Figure(go.Treemap(
36
- labels=[h['name'] for h in hospital_data],
37
- parents=[''] * len(hospital_data),
38
- values=[h['beds'] for h in hospital_data],
39
- text=[f"Sentiment Score: {sentiment_scores[h['name']]:.2f}" for h in hospital_data],
40
- hovertemplate='<b>%{label}</b><br>%{text}<br>Number of Beds: %{value}',
41
- ))
42
- fig.update_layout(title='Minnesota Hospital Beds and Sentiment Scores')
43
- st.plotly_chart(fig)
 
 
1
  import streamlit as st
2
+ import plotly.express as px
3
  import pandas as pd
4
+
5
+ # Define the Hugging Face model
6
+ @st.cache(allow_output_mutation=True)
7
+ def load_model():
8
+ model = <Hugging Face Model> # Replace with your own Hugging Face model
9
+ return model
10
+
11
+ # Define the top five largest hospitals in NJ
12
+ hospitals = [
13
+ {'name': 'Hackensack University Medical Center', 'beds': 974, 'latitude': 40.8875, 'longitude': -74.0344},
14
+ {'name': 'Robert Wood Johnson University Hospital', 'beds': 965, 'latitude': 40.4842, 'longitude': -74.4323},
15
+ {'name': 'Jersey Shore University Medical Center', 'beds': 621, 'latitude': 40.1876, 'longitude': -74.0575},
16
+ {'name': 'St. Joseph\'s University Medical Center', 'beds': 525, 'latitude': 40.9235, 'longitude': -74.1645},
17
+ {'name': 'Morristown Medical Center', 'beds': 506, 'latitude': 40.7878, 'longitude': -74.4873}
18
  ]
19
 
20
+ # Save the hospital data as a CSV file
21
+ df = pd.DataFrame(hospitals)
22
+ df.to_csv('hospitals.csv', index=False)
23
 
24
  # Define the Streamlit app
25
+ def app():
26
+ st.title('Hospital Data')
27
+
28
+ # Load the Hugging Face model
29
+ model = load_model()
30
+
31
+ # Get user input
32
+ text = st.text_input('Enter text to summarize')
33
+
34
+ # Generate summary using the Hugging Face model
35
+ summary = model(text)
36
+
37
+ # Display the summary
38
+ st.write('Summary:', summary)
39
+
40
+ # Create a treemap of the hospital data
41
+ fig = px.treemap(df, path=['name'], values='beds', color='beds', hover_data=['latitude', 'longitude'])
42
+ st.plotly_chart(fig)
43
+
44
+ # Run the Streamlit app
45
+ if __name__ == '__main__':
46
+ app()