hhalim commited on
Commit
3173639
1 Parent(s): e73d085

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -52
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 AutoModelWithLMHead
5
-
6
- # Create a list of the top five largest hospitals in the state of Minnesota
7
- hospitals_dict = [
8
- {'name': 'Mayo Clinic',
9
- 'number_beds': 1569,
10
- 'latitude': 44.074,
11
- 'longitude': -92.4591},
12
- {'name': 'United Hospital',
13
- 'number_beds': 663,
14
- 'latitude': 44.8794,
15
- 'longitude': -93.1748},
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
- # Create the dataframe from the list of dictionaries
31
- df = pd.DataFrame(hospitals_dict)
32
-
33
- # Create a treemap with plotly graph objects
34
- fig = go.Figure(data=go.Treemap(
35
- labels=df['name'],
36
- parents=['Minnesota'] * len(df),
37
- values=df['number_beds'],
38
- ))
39
-
40
- # Create the Huggingface model
41
- model = AutoModelWithLMHead.from_pretrained("distilbert-base-uncased")
42
-
43
- # Streamlit app
44
- st.title("Minnesota's Largest Hospitals")
45
-
46
- # Display the treemap
47
- st.plotly_chart(fig)
48
-
49
- # Display hospital information
50
- st.subheader("Hospital Information")
51
- st.write(df)
52
-
53
- # Save the dataframe as a CSV file
54
- st.subheader("Save CSV File")
55
- st.markdown("Click the button below to save the dataframe as a CSV file.")
56
- st.write(df.to_csv(index=False))
 
 
 
 
 
 
 
 
 
 
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()