awacke1 commited on
Commit
1e19d5c
1 Parent(s): cbb80ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -8
app.py CHANGED
@@ -1,13 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
- from transformers import pipeline
 
 
 
 
 
3
 
4
- st.title("Text Generation with Hugging Face")
 
 
 
5
 
6
- model_name = "gpt2"
7
- generator = pipeline("text-generation", model=model_name, device=0)
8
 
9
- prompt = st.text_input("Enter text prompt:", "Once upon a time")
 
 
10
 
11
- if st.button("Generate Text"):
12
- output = generator(prompt, max_length=100, do_sample=True)
13
- st.write(output[0]['generated_text'])
 
1
+ # Step 1: Install the required libraries
2
+ !pip install streamlit plotly transformers
3
+
4
+ # Step 2: Load the Huggingface model for sentiment analysis
5
+ import transformers
6
+ import torch
7
+
8
+ model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
9
+ tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
10
+ model = transformers.AutoModelForSequenceClassification.from_pretrained(model_name)
11
+
12
+ # Step 3: Create a function to analyze the sentiment of text using the Huggingface model
13
+ def analyze_sentiment(text):
14
+ inputs = tokenizer(text, return_tensors="pt")
15
+ outputs = model(**inputs)
16
+ scores = torch.nn.functional.softmax(outputs.logits, dim=1).detach().numpy()[0]
17
+ sentiment = scores.argmax()
18
+ return sentiment
19
+
20
+ # Step 4: Define a Python list dictionary of the top five largest hospitals in the state of Minnesota
21
+ hospital_data = [
22
+ {
23
+ "name": "Mayo Clinic",
24
+ "beds": 1500,
25
+ "latitude": 44.023501,
26
+ "longitude": -92.465032,
27
+ "url": "https://www.mayoclinic.org/appointments"
28
+ },
29
+ {
30
+ "name": "University of Minnesota Medical Center",
31
+ "beds": 1077,
32
+ "latitude": 44.969478,
33
+ "longitude": -93.236351,
34
+ "url": "https://www.mhealth.org/ummc"
35
+ },
36
+ {
37
+ "name": "Abbott Northwestern Hospital",
38
+ "beds": 1034,
39
+ "latitude": 44.952221,
40
+ "longitude": -93.266389,
41
+ "url": "https://www.allinahealth.org/locations/abbott-northwestern-hospital"
42
+ },
43
+ {
44
+ "name": "St. Cloud Hospital",
45
+ "beds": 489,
46
+ "latitude": 45.554935,
47
+ "longitude": -94.171829,
48
+ "url": "https://www.centracare.com/locations/st-cloud-hospital/"
49
+ },
50
+ {
51
+ "name": "Essentia Health-St. Mary's Medical Center",
52
+ "beds": 391,
53
+ "latitude": 46.783839,
54
+ "longitude": -92.103965,
55
+ "url": "https://www.essentiahealth.org/find-facility/profile/st-marys-medical-center-duluth/"
56
+ }
57
+ ]
58
+
59
+ # Step 5: Save the Python list dictionary as a CSV file
60
+ import csv
61
+
62
+ with open("hospital_data.csv", mode="w", newline="") as file:
63
+ writer = csv.DictWriter(file, fieldnames=["name", "beds", "latitude", "longitude", "url"])
64
+ writer.writeheader()
65
+ for hospital in hospital_data:
66
+ writer.writerow(hospital)
67
+
68
+ # Step 6: Create a Streamlit app that uses Plotly graph objects like treemap to visualize the sentiment analysis results and the hospital data
69
  import streamlit as st
70
+ import plotly.express as px
71
+
72
+ st.title("Sentiment Analysis and Hospital Data Visualization")
73
+
74
+ # Sentiment analysis section
75
+ st.header("Sentiment Analysis")
76
 
77
+ text = st.text_input("Enter some text:")
78
+ if text:
79
+ sentiment = analyze_sentiment(text)
80
+ st.write("Sentiment:", sentiment)
81
 
82
+ # Hospital data section
83
+ st.header("Hospital Data")
84
 
85
+ df = px.data.tips()
86
+ fig = px.treemap(hospital_data, path=["name"], values="beds", color="beds")
87
+ st.plotly_chart(fig)
88