awacke1 commited on
Commit
53da5ec
ยท
1 Parent(s): 1c737af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -84
app.py CHANGED
@@ -1,87 +1,102 @@
1
  import streamlit as st
2
- import pandas as pd
 
3
  import random
4
- import plotly.graph_objects as go
5
- import plotly.express as px
6
-
7
- def generate_health_conditions():
8
- return [
9
- {"condition": "๐Ÿ’” Heart disease", "emoji": "๐Ÿ’—", "spending": {"Minnesota": 100, "Florida": 150, "California": 200, "New York": 120, "Texas": 180}, "treatment": "Regular checkups with a cardiologist", "savings": "$1000"},
10
- {"condition": "๐Ÿค• Trauma-related disorders", "emoji": "๐Ÿš‘", "spending": {"Minnesota": 90, "Florida": 110, "California": 150, "New York": 100, "Texas": 130}, "treatment": "Counseling and physical therapy", "savings": "$500"},
11
- {"condition": "๐Ÿฆ€ Cancer", "emoji": "๐ŸŽ—๏ธ", "spending": {"Minnesota": 80, "Florida": 120, "California": 180, "New York": 100, "Texas": 150}, "treatment": "Early detection and treatment", "savings": "$2000"},
12
- {"condition": "๐Ÿง  Mental disorders", "emoji": "๐Ÿง˜", "spending": {"Minnesota": 70, "Florida": 100, "California": 140, "New York": 90, "Texas": 120}, "treatment": "Therapy and medication", "savings": "$1500"},
13
- {"condition": "๐Ÿฆด Osteoarthritis and joint disorders", "emoji": "๐Ÿฅ", "spending": {"Minnesota": 60, "Florida": 90, "California": 120, "New York": 80, "Texas": 100}, "treatment": "Low-impact exercise and physical therapy", "savings": "$800"},
14
- {"condition": "๐Ÿ’‰ Diabetes", "emoji": "๐Ÿฉธ", "spending": {"Minnesota": 50, "Florida": 80, "California": 100, "New York": 60, "Texas": 90}, "treatment": "Regular checkups and medication", "savings": "$1200"},
15
- {"condition": "๐Ÿซ Chronic obstructive pulmonary disease and asthma", "emoji": "๐Ÿซ€", "spending": {"Minnesota": 40, "Florida": 70, "California": 90, "New York": 50, "Texas": 80}, "treatment": "Inhalers and breathing exercises", "savings": "$600"},
16
- {"condition": "๐Ÿฉบ Hypertension", "emoji": "๐Ÿ’‰", "spending": {"Minnesota": 30, "Florida": 60, "California": 80, "New York": 40, "Texas": 70}, "treatment": "Lifestyle changes and medication", "savings": "$900"},
17
- {"condition": "๐Ÿ”ฌ Hyperlipidemia", "emoji": "๐Ÿ”ฌ", "spending": {"Minnesota": 20, "Florida": 50, "California": 70, "New York": 30, "Texas": 60}, "treatment": "Lifestyle changes and medication", "savings": "$700"},
18
- {"condition": "๐Ÿฆด Back problems", "emoji": "๐Ÿง", "spending": {"Minnesota": 10, "Florida": 40,
19
-
20
- def calculate_total_spending(health_conditions):
21
- total_spending = 0
22
- for condition in health_conditions:
23
- for state, spending in condition["spending"].items():
24
- total_spending += spending
25
- return round(total_spending, 1)
26
-
27
- def generate_sunburst_chart(health_conditions, total_spending):
28
- fig_sunburst = go.Figure(go.Treemap(
29
- labels=[f"{condition['emoji']} {condition['condition']} ({state})" for condition in health_conditions for state in condition['spending'].keys()],
30
- parents=[f"{condition['condition']} ({state})" for condition in health_conditions for state in condition['spending'].keys()],
31
- values=[spending for condition in health_conditions for spending in condition['spending'].values()],
32
- branchvalues="total",
33
- ))
34
-
35
- fig_sunburst.update_layout(
36
- title=f"Top Health Conditions in Different States by Spending (Total: ${total_spending}B)",
37
- margin=dict(l=0, r=0, t=50, b=0),
38
- )
39
- return fig_sunburst
40
-
41
- def roll(state, condition):
42
- frequencies = [random.randint(1, 10) for _ in range(1000)]
43
- spending = condition["spending"][state]
44
- frequencies = [round(frequency * spending / 100, 1) for frequency in frequencies]
45
- return frequencies
46
-
47
- def generate_bar_chart(state, condition, frequencies):
48
- fig_bar = px.bar(
49
- x=[f"Variant {i}" for i in range(1, 11)],
50
- y=frequencies[:10],
51
- labels={'x': 'Variant', 'y': 'Cost'},
52
- title=f"Variants of {condition['condition']} ({condition['emoji']}) in {state}",
53
- )
54
- return fig_bar
55
-
56
- def generate_recommendation(condition):
57
- return f"Based on the severity of your {condition['condition']}, we recommend {condition['treatment']} for early treatment. This could save you up to {condition['savings']} in healthcare costs."
58
-
59
- def main():
60
- states = ["Minnesota", "Florida", "California", "New York", "Texas"]
61
- top_n = 10
62
-
63
- health_conditions = generate_health_conditions()
64
-
65
- total_spending = calculate_total_spending(health_conditions)
66
-
67
- fig_sunburst = generate_sunburst_chart(health_conditions, total_spending)
68
-
69
- st.plotly_chart(fig_sunburst)
70
-
71
- condition_idx = st.selectbox("Select your current health condition", range(top_n))
72
-
73
- condition = health_conditions[condition_idx]
74
-
75
- st.write(generate_recommendation(condition))
76
-
77
- state = st.selectbox("Select your state", states)
78
-
79
- frequencies = roll(state, condition)
80
-
81
- fig_bar = generate_bar_chart(state, condition, frequencies)
82
-
83
- st.plotly_chart(fig_bar)
84
-
85
- if __name__ == "__main__":
86
- main()
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from graphviz import Digraph
3
+ import time
4
  import random
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ # Define the emoji to use for the swim lanes
7
+ SWIM_LANES = {
8
+ "Data Pipelines": "๐Ÿ”",
9
+ "Build and Train Models": "๐Ÿงช",
10
+ "Deploy and Predict": "๐Ÿš€"
11
+ }
12
+
13
+ # Define the graph structure
14
+ graph = Digraph()
15
+ graph.attr(rankdir="TB") # Top to Bottom or LR Left to Right
16
+ graph.attr(fontsize="20")
17
+ graph.attr(compound="true")
18
+ graph.attr(nodesep="0.5")
19
+
20
+ # Define the nodes
21
+ graph.node("๐Ÿ“Š Data Collection")
22
+ graph.node("๐Ÿงน Data Cleaning")
23
+ graph.node("๐Ÿ”ง Data Transformation")
24
+ graph.node("๐Ÿ”Ž Feature Engineering")
25
+ graph.node("โš™๏ธ Model Selection")
26
+ graph.node("๐ŸŽ“ Model Training")
27
+ graph.node("๐Ÿšข Model Deployment")
28
+ graph.node("๐Ÿ“ก Model Serving")
29
+ graph.node("๐Ÿ”ฎ Predictions")
30
+ graph.node("๐Ÿ‘ Feedback Collection")
31
+ graph.node("๐Ÿค” Feedback Processing")
32
+ graph.node("โœ๏ธ Model Updating")
33
+
34
+ # Add the edges
35
+ graph.edge("๐Ÿ“Š Data Collection", "๐Ÿงน Data Cleaning")
36
+ graph.edge("๐Ÿงน Data Cleaning", "๐Ÿ”ง Data Transformation")
37
+ graph.edge("๐Ÿ”ง Data Transformation", "๐Ÿ”Ž Feature Engineering")
38
+ graph.edge("๐Ÿ”Ž Feature Engineering", "โš™๏ธ Model Selection")
39
+ graph.edge("โš™๏ธ Model Selection", "๐ŸŽ“ Model Training")
40
+ graph.edge("๐ŸŽ“ Model Training", "๐Ÿšข Model Deployment")
41
+ graph.edge("๐Ÿšข Model Deployment", "๐Ÿ“ก Model Serving")
42
+ graph.edge("๐Ÿ“ก Model Serving", "๐Ÿ”ฎ Predictions")
43
+ graph.edge("๐Ÿ”ฎ Predictions", "๐Ÿ‘ Feedback Collection")
44
+ graph.edge("๐Ÿ‘ Feedback Collection", "๐Ÿค” Feedback Processing")
45
+ graph.edge("๐Ÿค” Feedback Processing", "โœ๏ธ Model Updating")
46
+ graph.edge("โœ๏ธ Model Updating", "๐ŸŽ“ Model Training")
47
+
48
+ # Add the swim lanes
49
+ with graph.subgraph(name="cluster_0") as c:
50
+ c.attr(rank="1")
51
+ c.attr(label=SWIM_LANES["Data Pipelines"])
52
+ c.edge("๐Ÿ“Š Data Collection", "๐Ÿงน Data Cleaning", style="invis")
53
+ c.edge("๐Ÿงน Data Cleaning", "๐Ÿ”ง Data Transformation", style="invis")
54
+
55
+ with graph.subgraph(name="cluster_1") as c:
56
+ c.attr(rank="2")
57
+ c.attr(label=SWIM_LANES["Build and Train Models"])
58
+ c.edge("๐Ÿ”Ž Feature Engineering", "โš™๏ธ Model Selection", style="invis")
59
+ c.edge("โš™๏ธ Model Selection", "๐ŸŽ“ Model Training", style="invis")
60
+
61
+ with graph.subgraph(name="cluster_2") as c:
62
+ c.attr(rank="3")
63
+ c.attr(label=SWIM_LANES["Deploy and Predict"])
64
+ c.edge("๐Ÿšข Model Deployment", "๐Ÿ“ก Model Serving", style="invis")
65
+ c.edge("๐Ÿ“ก Model Serving", "๐Ÿ”ฎ Predictions", style="invis")
66
+
67
+ with graph.subgraph(name="cluster_3") as c:
68
+ c.attr(rank="4")
69
+ c.attr(label="Reinforcement Learning Human Feedback")
70
+ c.edge("๐Ÿ”ฎ Predictions", "๐Ÿ‘ Feedback Collection", style="invis")
71
+ c.edge("๐Ÿ‘ Feedback Collection", "๐Ÿค” Feedback Processing", style="invis")
72
+ c.edge("๐Ÿค” Feedback Processing", "โœ๏ธ Model Updating", style="invis")
73
+
74
+ def render_graph():
75
+ st.graphviz_chart(graph.source)
76
+
77
+ def update_graph():
78
+ for i in range(60):
79
+ # Update the graph with new inputs randomly
80
+ graph.node("๐Ÿ“Š Data Collection", label=f"๐Ÿ“Š Data Collection\nData {random.randint(0,100)}")
81
+ graph.node("๐Ÿงน Data Cleaning", label=f"๐Ÿงน Data Cleaning\nCleaned Data {random.randint(0,100)}")
82
+ graph.node("๐Ÿ”ง Data Transformation", label=f"๐Ÿ”ง Data Transformation\nTransformed Data {random.randint(0,100)}")
83
+ graph.node("๐Ÿ”Ž Feature Engineering", label=f"๐Ÿ”Ž Feature Engineering\nFeatures {random.randint(0,100)}")
84
+ graph.node("โš™๏ธ Model Selection", label=f"โš™๏ธ Model Selection\nSelected Model {random.randint(0,100)}")
85
+ graph.node("๐ŸŽ“ Model Training", label=f"๐ŸŽ“ Model Training\nTrained Model {random.randint(0,100)}")
86
+ graph.node("๐Ÿšข Model Deployment", label=f"๐Ÿšข Model Deployment\nDeployed Model {random.randint(0,100)}")
87
+ graph.node("๐Ÿ“ก Model Serving", label=f"๐Ÿ“ก Model Serving\nServed Model {random.randint(0,100)}")
88
+ graph.node("๐Ÿ”ฎ Predictions", label=f"๐Ÿ”ฎ Predictions\nPredicted Results {random.randint(0,100)}")
89
+ graph.node("๐Ÿ‘ Feedback Collection", label=f"๐Ÿ‘ Feedback Collection\nFeedback {random.randint(0,100)}")
90
+ graph.node("๐Ÿค” Feedback Processing", label=f"๐Ÿค” Feedback Processing\nProcessed Feedback {random.randint(0,100)}")
91
+ graph.node("โœ๏ธ Model Updating", label=f"โœ๏ธ Model Updating\nUpdated Model {random.randint(0,100)}")
92
+
93
+ # Render the updated graph
94
+ render_graph()
95
+
96
+ # Wait for 1 second
97
+ time.sleep(1)
98
+ # Render the initial graph
99
+ render_graph()
100
+
101
+ # Update the graph every second for 60 seconds
102
+ update_graph()