sanjayw's picture
Update app.py
8f73dc0
import streamlit as st
import plotly.graph_objects as go
import pandas as pd
#from transformers import pipeline
# Define a list of dictionaries containing hospital data
hospitals = [
{
'name': 'Hackensack University Medical Center',
'beds': 775,
'lat': 40.9008,
'lon': -74.0679
},
{
'name': 'Robert Wood Johnson University Hospital',
'beds': 965,
'lat': 40.4862,
'lon': -74.4518
},
{
'name': 'Atlantic Health System - Morristown Medical Center',
'beds': 712,
'lat': 40.7869,
'lon': -74.4774
},
{
'name': 'Jersey Shore University Medical Center',
'beds': 646,
'lat': 40.1955,
'lon': -74.0636
},
{
'name': 'Cooper University Hospital',
'beds': 635,
'lat': 39.9384,
'lon': -75.1181
}
]
# Save the hospital data to a CSV file
df = pd.DataFrame(hospitals)
df.to_csv('hospitals.csv', index=False)
# Load the Hugging Face model
#model = pipeline('sentiment-analysis')
# Define a function to analyze the sentiment of hospital names
def analyze_sentiment(text):
result = model(text)
score = result[0]['score']
label = result[0]['label']
return score, label
# Analyze the sentiment of each hospital name
for hospital in hospitals:
score, label = analyze_sentiment(hospital['name'])
hospital['sentiment_score'] = score
hospital['sentiment_label'] = label
# Sort the hospitals by number of beds
sorted_hospitals = sorted(hospitals, key=lambda x: x['beds'], reverse=True)
# Get the top 5 hospitals
top_hospitals = sorted_hospitals[:5]
# Create a treemap of hospital bed counts in New Jersey
fig = go.Figure(
go.Treemap(
labels=[hospital['name'] for hospital in sorted_hospitals],
parents=['New Jersey' for hospital in sorted_hospitals],
values=[hospital['beds'] for hospital in sorted_hospitals],
text=[f"{hospital['name']}<br>Beds: {hospital['beds']}" for hospital in sorted_hospitals],
hovertemplate='<b>%{label}</b><br>%{text}<extra></extra>'
)
)
fig.update_layout(
title='Hospital Bed Counts in New Jersey',
margin=dict(t=50, l=25, r=25, b=25),
)
# Display the treemap and top 5 hospitals
st.plotly_chart(fig)
st.write('**Top 5 Hospitals in New Jersey**')
for i, hospital in enumerate(top_hospitals):
st.write(f"{i+1}. {hospital['name']} - Beds: {hospital['beds']} - Latitude: {hospital['lat']} - Longitude: {hospital['lon']}")