rehanafzal commited on
Commit
380a0b9
·
verified ·
1 Parent(s): 945c58e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -0
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from groq import Groq
3
+
4
+ # Set API Key (Replace with your actual API key)
5
+ os.environ["GROQ_API_KEY"] = "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"
6
+
7
+ # Initialize the Groq Client
8
+ client = Groq(api_key=os.environ["GROQ_API_KEY"])
9
+
10
+ # Test Query
11
+ chat_completion = client.chat.completions.create(
12
+ messages=[{"role": "user", "content": "Explain the importance of fast language models"}],
13
+ model="llama-3.3-70b-versatile",
14
+ )
15
+
16
+ # Print response
17
+ print(chat_completion.choices[0].message.content)
18
+ import random
19
+ import time
20
+ import pandas as pd
21
+
22
+ # Function to simulate data updates
23
+ def get_real_time_data():
24
+ return {
25
+ "Heart Rate (BPM)": random.randint(60, 120),
26
+ "Oxygen Saturation (%)": round(random.uniform(85, 100), 1),
27
+ "Blood Pressure (mmHg)": f"{random.randint(90, 120)}/{random.randint(60, 80)}",
28
+ "Respiratory Rate (BPM)": random.randint(12, 20),
29
+ "Hydration Level (%)": round(random.uniform(40, 100), 1),
30
+ "Battery Level (%)": random.randint(10, 100),
31
+ "Food Supply (Days)": random.randint(1, 10),
32
+ "Water Supply (Liters)": random.randint(1, 50),
33
+ }
34
+
35
+ # Testing the function
36
+ for _ in range(5):
37
+ print(get_real_time_data())
38
+ time.sleep(1)
39
+
40
+ def predict_survival_time(data):
41
+ oxygen_factor = data["Oxygen Saturation (%)"] / 100
42
+ hydration_factor = data["Hydration Level (%)"] / 100
43
+ battery_factor = data["Battery Level (%)"] / 100
44
+ food_factor = data["Food Supply (Days)"] / 10
45
+
46
+ survival_hours = (oxygen_factor + hydration_factor + battery_factor + food_factor) * 10
47
+ return round(survival_hours, 2)
48
+
49
+ # Example test
50
+ sample_data = get_real_time_data()
51
+ print("Predicted Survival Time (Hours):", predict_survival_time(sample_data))
52
+
53
+ import streamlit as st
54
+ import pandas as pd
55
+ import random
56
+ import time
57
+
58
+ st.title("🚀 Astronaut Survival Monitor")
59
+
60
+ # Simulating real-time data updates
61
+ def get_real_time_data():
62
+ return {
63
+ "Heart Rate (BPM)": random.randint(60, 120),
64
+ "Oxygen Saturation (%)": round(random.uniform(85, 100), 1),
65
+ "Blood Pressure (mmHg)": f"{random.randint(90, 120)}/{random.randint(60, 80)}",
66
+ "Respiratory Rate (BPM)": random.randint(12, 20),
67
+ "Hydration Level (%)": round(random.uniform(40, 100), 1),
68
+ "Battery Level (%)": random.randint(10, 100),
69
+ "Food Supply (Days)": random.randint(1, 10),
70
+ "Water Supply (Liters)": random.randint(1, 50),
71
+ }
72
+
73
+ # Survival Time Prediction
74
+ def predict_survival_time(data):
75
+ oxygen_factor = data["Oxygen Saturation (%)"] / 100
76
+ hydration_factor = data["Hydration Level (%)"] / 100
77
+ battery_factor = data["Battery Level (%)"] / 100
78
+ food_factor = data["Food Supply (Days)"] / 10
79
+
80
+ survival_hours = (oxygen_factor + hydration_factor + battery_factor + food_factor) * 10
81
+ return round(survival_hours, 2)
82
+
83
+ # Real-time simulation
84
+ data = get_real_time_data()
85
+ survival_time = predict_survival_time(data)
86
+
87
+ st.metric("Predicted Survival Time", f"{survival_time} Hours")
88
+
89
+ # Display real-time health and resource data
90
+ st.write("### Health Metrics")
91
+ for key, value in data.items():
92
+ st.metric(key, value)
93
+
94
+ st.warning("🚨 Alert: Low Oxygen or Power Levels Detected!") if data["Oxygen Saturation (%)"] < 90 or data["Battery Level (%)"] < 20 else None