awacke1 commited on
Commit
4f6ea8d
·
1 Parent(s): be413d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -35
app.py CHANGED
@@ -1,10 +1,8 @@
1
- import pandas as pd
2
  import streamlit as st
3
  from graphviz import Digraph
4
 
5
  st.set_page_config(page_title="Ideal Care Plan for Top 10 Health Conditions")
6
 
7
- # Create a pandas dataframe for the top 10 health conditions and their spending
8
  health_conditions = [
9
  {"condition": "Heart disease ❤️", "spending": 214.3},
10
  {"condition": "Trauma-related disorders 🤕", "spending": 198.6},
@@ -18,37 +16,36 @@ health_conditions = [
18
  {"condition": "Back problems 👨‍⚕️", "spending": 67.0},
19
  ]
20
 
21
- df = pd.DataFrame(health_conditions)
22
-
23
- # Create Graphviz graph object
24
- graph = Digraph(comment="Ideal Care Plan for Top 10 Health Conditions")
25
- graph.graph_attr["rankdir"] = "LR" # left to right layout
26
-
27
- # Add nodes to the graph for each health condition
28
- for i, row in df.iterrows():
29
- condition = row["condition"]
30
- spending = row["spending"]
31
-
32
- # Add node to the graph with hyperlink based on condition
33
- if i < 3:
34
- url = f"https://www.cdc.gov/{condition.split()[0].lower()}"
35
  else:
36
- url = None
37
- graph.node(condition, f"{condition}\n${spending:.1f}B", href=url)
38
-
39
- # Add edges to the graph based on related conditions
40
- graph.edge("Heart disease ❤️", "Hypertension 🩺")
41
- graph.edge("Heart disease ❤️", "Hyperlipidemia 🍔")
42
- graph.edge("Trauma-related disorders 🤕", "Mental disorders 🧠")
43
- graph.edge("Cancer 🦀", "Heart disease ❤️")
44
- graph.edge("Cancer 🦀", "Trauma-related disorders 🤕")
45
- graph.edge("Cancer 🦀", "Osteoarthritis and joint disorders 🦴")
46
- graph.edge("Mental disorders 🧠", "Heart disease ❤️")
47
- graph.edge("Mental disorders 🧠", "Trauma-related disorders 🤕")
48
- graph.edge("Osteoarthritis and joint disorders 🦴", "Back problems 👨‍⚕️")
49
- graph.edge("Diabetes 🍬", "Heart disease ❤️")
50
- graph.edge("Diabetes 🍬", "Hypertension 🩺")
51
- graph.edge("Chronic obstructive pulmonary disease and asthma 🫁", "Heart disease ❤️")
52
-
53
- # Render the graph as an image and display in Streamlit app
54
- st.graphviz_chart(graph.pipe(format="svg"))
 
 
1
  import streamlit as st
2
  from graphviz import Digraph
3
 
4
  st.set_page_config(page_title="Ideal Care Plan for Top 10 Health Conditions")
5
 
 
6
  health_conditions = [
7
  {"condition": "Heart disease ❤️", "spending": 214.3},
8
  {"condition": "Trauma-related disorders 🤕", "spending": 198.6},
 
16
  {"condition": "Back problems 👨‍⚕️", "spending": 67.0},
17
  ]
18
 
19
+ urls = {
20
+ "Heart disease ❤️": "https://www.cdc.gov/heartdisease",
21
+ "Trauma-related disorders 🤕": "https://www.nimh.nih.gov/health/topics/post-traumatic-stress-disorder-ptsd/index.shtml",
22
+ "Cancer 🦀": "https://www.cancer.gov/",
23
+ }
24
+
25
+ dot = Digraph(comment="Ideal Care Plan for Top 10 Health Conditions")
26
+ dot.graph_attr["rankdir"] = "LR"
27
+ for condition in health_conditions:
28
+ name = condition["condition"]
29
+ spending = condition["spending"]
30
+ if name in urls:
31
+ url = urls[name]
32
+ dot.node(name, f"{name}\n${spending:.1f}B", href=url)
33
  else:
34
+ dot.node(name, f"{name}\n${spending:.1f}B")
35
+
36
+ dot.edges([
37
+ ("Heart disease ❤️", "Hypertension 🩺"),
38
+ ("Heart disease ❤️", "Hyperlipidemia 🍔"),
39
+ ("Trauma-related disorders 🤕", "Mental disorders 🧠"),
40
+ ("Cancer 🦀", "Heart disease ❤️"),
41
+ ("Cancer 🦀", "Trauma-related disorders 🤕"),
42
+ ("Cancer 🦀", "Osteoarthritis and joint disorders 🦴"),
43
+ ("Mental disorders 🧠", "Heart disease ❤️"),
44
+ ("Mental disorders 🧠", "Trauma-related disorders 🤕"),
45
+ ("Osteoarthritis and joint disorders 🦴", "Back problems 👨‍⚕️"),
46
+ ("Diabetes 🍬", "Heart disease ❤️"),
47
+ ("Diabetes 🍬", "Hypertension 🩺"),
48
+ ("Chronic obstructive pulmonary disease and asthma 🫁", "Heart disease ❤️"),
49
+ ])
50
+
51
+ st.graphviz_chart(dot.pipe(format="svg"))