Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,95 +1,41 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
-
import
|
| 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 = "
|
| 11 |
client = Groq(api_key=GROQ_API_KEY)
|
| 12 |
|
| 13 |
-
st.title("
|
|
|
|
| 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 |
-
|
| 38 |
-
|
| 39 |
-
st.
|
| 40 |
-
|
| 41 |
-
# Display basic statistics
|
| 42 |
-
if not data.empty:
|
| 43 |
-
st.write("### Dataset Summary")
|
| 44 |
-
st.write(data.describe())
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
|
| 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 |
-
#
|
| 60 |
-
|
| 61 |
-
|
| 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 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 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.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
from groq import Groq # Ensure Groq client library is installed
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Initialize Groq API
|
| 6 |
+
GROQ_API_KEY = "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"
|
| 7 |
client = Groq(api_key=GROQ_API_KEY)
|
| 8 |
|
| 9 |
+
st.title("AI Prediction with Groq API")
|
| 10 |
+
uploaded_file = st.file_uploader("Upload your mission dataset (CSV)", type=["csv"])
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
if uploaded_file:
|
| 13 |
+
# Read the dataset
|
| 14 |
+
df = pd.read_csv(uploaded_file)
|
| 15 |
+
st.dataframe(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# Select mission ID for prediction
|
| 18 |
+
mission_ids = df["Mission ID"].unique()
|
| 19 |
+
selected_mission_id = st.selectbox("Select Mission ID for prediction:", mission_ids)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# Display selected mission details
|
| 22 |
+
mission_data = df[df["Mission ID"] == selected_mission_id].iloc[0]
|
| 23 |
+
st.write("Selected Mission Data:", mission_data)
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
if st.button("Predict Resource Optimization"):
|
| 26 |
+
# Prepare data payload
|
| 27 |
+
payload = {
|
| 28 |
+
"id": int(mission_data["Mission ID"]),
|
| 29 |
+
"distance_from_earth": float(mission_data["Distance from Earth (light-years)"]),
|
| 30 |
+
"duration": float(mission_data["Mission Duration (years)"]),
|
| 31 |
+
"crew_size": int(mission_data["Crew Size"]),
|
| 32 |
+
"fuel_consumption": float(mission_data["Fuel Consumption (tons)"]),
|
| 33 |
+
"payload_weight": float(mission_data["Payload Weight (tons)"])
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# Call the Groq API
|
| 37 |
+
try:
|
| 38 |
+
response = client.predict(payload)
|
| 39 |
+
st.success(f"Prediction Result: {response}")
|
| 40 |
+
except Exception as e:
|
| 41 |
+
st.error(f"Error: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|