Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,95 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
import numpy as np
|
|
|
|
|
|
|
| 4 |
from groq import Groq # Assuming this is the correct import
|
|
|
|
| 5 |
|
| 6 |
# Initialize Groq API
|
| 7 |
GROQ_API_KEY = "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"
|
| 8 |
client = Groq(api_key=GROQ_API_KEY)
|
| 9 |
|
| 10 |
-
|
| 11 |
-
RESOURCE_LIMITS = {
|
| 12 |
-
"Oxygen Level": (80, 100),
|
| 13 |
-
"Food Reserves (days)": (10, 365),
|
| 14 |
-
"Power Availability (%)": (30, 100),
|
| 15 |
-
"Communication Signals (Strength)": (50, 100),
|
| 16 |
-
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
"
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
return f"Error using Groq API: {e}"
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
-
st.write("
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
st.write("###
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
st.
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
st.
|
| 63 |
-
st.warning(alert_message)
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import seaborn as sns
|
| 6 |
from groq import Groq # Assuming this is the correct import
|
| 7 |
+
import requests
|
| 8 |
|
| 9 |
# Initialize Groq API
|
| 10 |
GROQ_API_KEY = "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"
|
| 11 |
client = Groq(api_key=GROQ_API_KEY)
|
| 12 |
|
| 13 |
+
st.title("Space Mission Analysis Dashboard")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Load dataset
|
| 16 |
+
data = pd.DataFrame({
|
| 17 |
+
"Mission ID": [],
|
| 18 |
+
"Mission Name": [],
|
| 19 |
+
"Launch Date": [],
|
| 20 |
+
"Target Type": [],
|
| 21 |
+
"Target Name": [],
|
| 22 |
+
"Mission Type": [],
|
| 23 |
+
"Distance from Earth (light-years)": [],
|
| 24 |
+
"Mission Duration (years)": [],
|
| 25 |
+
"Mission Cost (billion USD)": [],
|
| 26 |
+
"Scientific Yield (points)": [],
|
| 27 |
+
"Crew Size": [],
|
| 28 |
+
"Mission Success (%)": [],
|
| 29 |
+
"Fuel Consumption (tons)": [],
|
| 30 |
+
"Payload Weight (tons)": [],
|
| 31 |
+
"Launch Vehicle": []
|
| 32 |
+
})
|
| 33 |
|
| 34 |
+
# Upload dataset
|
| 35 |
+
uploaded_file = st.file_uploader("Upload your dataset (CSV format)", type=["csv"])
|
| 36 |
+
if uploaded_file:
|
| 37 |
+
data = pd.read_csv(uploaded_file)
|
| 38 |
+
st.write("### Dataset Preview")
|
| 39 |
+
st.write(data.head())
|
|
|
|
| 40 |
|
| 41 |
+
# Display basic statistics
|
| 42 |
+
if not data.empty:
|
| 43 |
+
st.write("### Dataset Summary")
|
| 44 |
+
st.write(data.describe())
|
| 45 |
|
| 46 |
+
# Visualization: Mission Success vs. Scientific Yield
|
| 47 |
+
st.write("### Mission Success vs. Scientific Yield")
|
| 48 |
+
plt.figure(figsize=(10, 5))
|
| 49 |
+
sns.scatterplot(
|
| 50 |
+
data=data,
|
| 51 |
+
x="Mission Success (%)",
|
| 52 |
+
y="Scientific Yield (points)",
|
| 53 |
+
hue="Mission Type",
|
| 54 |
+
palette="viridis"
|
| 55 |
+
)
|
| 56 |
+
plt.title("Success Rate vs Yield")
|
| 57 |
+
st.pyplot(plt)
|
| 58 |
|
| 59 |
+
# Filterable Data Selection
|
| 60 |
+
st.write("### Filtered Data Selection")
|
| 61 |
+
mission_types = data["Mission Type"].unique()
|
| 62 |
+
selected_type = st.selectbox("Select Mission Type", mission_types)
|
| 63 |
+
filtered_data = data[data["Mission Type"] == selected_type]
|
| 64 |
+
st.write(filtered_data)
|
| 65 |
|
| 66 |
+
# Groq API Call Example
|
| 67 |
+
st.write("### AI Prediction with Groq API")
|
| 68 |
+
sample_input = {
|
| 69 |
+
"mission_duration": filtered_data["Mission Duration (years)"].mean(),
|
| 70 |
+
"fuel_consumption": filtered_data["Fuel Consumption (tons)"].mean(),
|
| 71 |
+
"success_rate": filtered_data["Mission Success (%)"].mean(),
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if st.button("Predict Resource Optimization"):
|
| 75 |
+
response = requests.post(
|
| 76 |
+
"https://api.groq.com/v1/predict", # Replace with actual endpoint
|
| 77 |
+
headers={"Authorization": f"Bearer {GROQ_API_KEY}"},
|
| 78 |
+
json=sample_input
|
| 79 |
+
)
|
| 80 |
+
if response.status_code == 200:
|
| 81 |
+
prediction = response.json()
|
| 82 |
+
st.write("### AI Prediction Result")
|
| 83 |
+
st.json(prediction)
|
| 84 |
+
else:
|
| 85 |
+
st.error("Error: Could not get prediction")
|
| 86 |
|
| 87 |
+
# Insights: Fuel Efficiency Analysis
|
| 88 |
+
st.write("### Fuel Efficiency Analysis")
|
| 89 |
+
data["Fuel Efficiency (Yield per Ton)"] = (
|
| 90 |
+
data["Scientific Yield (points)"] / data["Fuel Consumption (tons)"]
|
| 91 |
+
).replace([np.inf, -np.inf], np.nan).dropna()
|
| 92 |
+
st.line_chart(data["Fuel Efficiency (Yield per Ton)"])
|
|
|
|
| 93 |
|
| 94 |
+
else:
|
| 95 |
+
st.warning("Please upload a valid CSV dataset.")
|