Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,53 @@
|
|
1 |
-
import plotly.graph_objects as go
|
2 |
import streamlit as st
|
|
|
|
|
3 |
import pandas as pd
|
4 |
-
from transformers import
|
5 |
-
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
{
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
{'name': 'Allina Health',
|
17 |
-
'number_beds': 600,
|
18 |
-
'latitude': 44.9352,
|
19 |
-
'longitude': -93.0614},
|
20 |
-
{'name': 'Fairview Southdale Hospital',
|
21 |
-
'number_beds': 446,
|
22 |
-
'latitude': 44.8552,
|
23 |
-
'longitude': -93.3455},
|
24 |
-
{'name': 'St. Cloud Hospital',
|
25 |
-
'number_beds': 437,
|
26 |
-
'latitude': 45.5517,
|
27 |
-
'longitude': -94.1613}
|
28 |
]
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import plotly.express as px
|
3 |
+
import plotly.graph_objects as go
|
4 |
import pandas as pd
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Define the Hugging Face model pipeline
|
8 |
+
nlp = pipeline("sentiment-analysis")
|
9 |
+
|
10 |
+
# Define the hospital data as a Python list of dictionaries
|
11 |
+
hospital_data = [
|
12 |
+
{"name": "Mayo Clinic", "beds": 1392, "latitude": 44.0205, "longitude": -92.4630},
|
13 |
+
{"name": "University of Minnesota Medical Center", "beds": 908, "latitude": 44.9737, "longitude": -93.2278},
|
14 |
+
{"name": "Abbott Northwestern Hospital", "beds": 631, "latitude": 44.9482, "longitude": -93.2616},
|
15 |
+
{"name": "St. Cloud Hospital", "beds": 489, "latitude": 45.5563, "longitude": -94.1672},
|
16 |
+
{"name": "Fairview Southdale Hospital", "beds": 342, "latitude": 44.8788, "longitude": -93.3521}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
]
|
18 |
|
19 |
+
# Save the hospital data as a CSV file
|
20 |
+
hospital_df = pd.DataFrame(hospital_data)
|
21 |
+
hospital_df.to_csv("hospital_data.csv", index=False)
|
22 |
+
|
23 |
+
# Define the Streamlit app
|
24 |
+
def app():
|
25 |
+
# Set the app title
|
26 |
+
st.title("Minnesota Hospital Data")
|
27 |
+
|
28 |
+
# Load the hospital data from the CSV file
|
29 |
+
hospital_df = pd.read_csv("hospital_data.csv")
|
30 |
+
|
31 |
+
# Display the hospital data as a table
|
32 |
+
st.write("Hospital Data:", hospital_df)
|
33 |
+
|
34 |
+
# Analyze the sentiment of the hospital names using the Hugging Face model
|
35 |
+
sentiment_scores = [nlp(hospital["name"])[0]["score"] for hospital in hospital_data]
|
36 |
+
sentiment_colors = ["red" if score < 0.5 else "green" for score in sentiment_scores]
|
37 |
+
hospital_df["sentiment_score"] = sentiment_scores
|
38 |
+
|
39 |
+
# Create a treemap chart of the hospital data
|
40 |
+
treemap_fig = px.treemap(hospital_df, path=["name"], values="beds",
|
41 |
+
color="sentiment_score", color_continuous_scale=["red", "green"],
|
42 |
+
hover_data=["latitude", "longitude"])
|
43 |
+
treemap_fig.update_traces(hovertemplate="<b>%{label}</b><br>Beds: %{value}<br>Latitude: %{customdata[0]}<br>Longitude: %{customdata[1]}")
|
44 |
+
treemap_fig.update_layout(margin=dict(t=25, b=25, r=25, l=25))
|
45 |
+
st.plotly_chart(treemap_fig)
|
46 |
+
|
47 |
+
# Display the top five largest hospitals in Minnesota
|
48 |
+
st.subheader("Top 5 Largest Hospitals in Minnesota")
|
49 |
+
largest_hospitals = hospital_df.nlargest(5, "beds")
|
50 |
+
st.write(largest_hospitals)
|
51 |
+
|
52 |
+
if __name__ == "__main__":
|
53 |
+
app()
|