Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,21 @@
|
|
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
|
55 |
-
import
|
56 |
-
|
|
|
|
|
|
|
57 |
|
58 |
-
|
|
|
|
|
59 |
|
60 |
-
#
|
61 |
def get_real_time_data():
|
62 |
return {
|
63 |
"Heart Rate (BPM)": random.randint(60, 120),
|
@@ -70,25 +28,41 @@ def get_real_time_data():
|
|
70 |
"Water Supply (Liters)": random.randint(1, 50),
|
71 |
}
|
72 |
|
73 |
-
# Survival
|
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-
|
84 |
data = get_real_time_data()
|
85 |
survival_time = predict_survival_time(data)
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
st.
|
93 |
-
|
94 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import random
|
3 |
import time
|
4 |
import pandas as pd
|
5 |
+
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
import streamlit as st
|
7 |
+
import plotly.graph_objects as go
|
8 |
+
from groq import Groq
|
9 |
+
|
10 |
+
# Set API Key (Replace with actual key)
|
11 |
+
os.environ["GROQ_API_KEY"] = "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"
|
12 |
+
client = Groq(api_key=os.environ["GROQ_API_KEY"])
|
13 |
|
14 |
+
# Streamlit UI Setup
|
15 |
+
st.set_page_config(page_title="π ARMS: Astronaut Survival Monitor", layout="wide")
|
16 |
+
st.title("π ARMS: Astronaut Resource Management System")
|
17 |
|
18 |
+
# Real-time Data Simulation
|
19 |
def get_real_time_data():
|
20 |
return {
|
21 |
"Heart Rate (BPM)": random.randint(60, 120),
|
|
|
28 |
"Water Supply (Liters)": random.randint(1, 50),
|
29 |
}
|
30 |
|
31 |
+
# Survival Prediction Function
|
32 |
def predict_survival_time(data):
|
33 |
oxygen_factor = data["Oxygen Saturation (%)"] / 100
|
34 |
hydration_factor = data["Hydration Level (%)"] / 100
|
35 |
battery_factor = data["Battery Level (%)"] / 100
|
36 |
food_factor = data["Food Supply (Days)"] / 10
|
|
|
37 |
survival_hours = (oxygen_factor + hydration_factor + battery_factor + food_factor) * 10
|
38 |
return round(survival_hours, 2)
|
39 |
|
40 |
+
# Generate Real-Time Data
|
41 |
data = get_real_time_data()
|
42 |
survival_time = predict_survival_time(data)
|
43 |
|
44 |
+
# Layout
|
45 |
+
col1, col2 = st.columns(2)
|
46 |
+
|
47 |
+
with col1:
|
48 |
+
st.metric("Predicted Survival Time", f"{survival_time} Hours")
|
49 |
+
st.subheader("π Health Metrics")
|
50 |
+
for key, value in data.items():
|
51 |
+
st.metric(key, value)
|
52 |
+
if data["Oxygen Saturation (%)"] < 90 or data["Battery Level (%)"] < 20:
|
53 |
+
st.warning("π¨ Critical Alert: Oxygen or Battery Levels are Low!")
|
54 |
+
|
55 |
+
with col2:
|
56 |
+
st.subheader("π Resource & Health Trends")
|
57 |
+
df = pd.DataFrame({"Metric": list(data.keys()), "Value": list(data.values())})
|
58 |
+
fig = go.Figure([go.Bar(x=df["Metric"], y=df["Value"], marker_color='crimson')])
|
59 |
+
fig.update_layout(title="Current Status of Astronaut Resources", xaxis_title="Metric", yaxis_title="Value")
|
60 |
+
st.plotly_chart(fig)
|
61 |
+
|
62 |
+
# AI-generated Advisory (Groq API)
|
63 |
+
st.subheader("π€ AI Advisor Suggestions")
|
64 |
+
response = client.chat.completions.create(
|
65 |
+
messages=[{"role": "user", "content": "Give survival improvement tips for astronauts."}],
|
66 |
+
model="llama-3.3-70b-versatile",
|
67 |
+
)
|
68 |
+
st.info(response.choices[0].message.content)
|