sanjayw commited on
Commit
5fbed17
·
1 Parent(s): c9935c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)