Afeefa123 commited on
Commit
74bc5ba
·
verified ·
1 Parent(s): e2e94f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -49
app.py CHANGED
@@ -1,65 +1,95 @@
1
  import streamlit as st
2
- from transformers import pipeline
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
- # Mock Resource Monitoring System
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
- def fetch_health_data():
19
- """Simulate fetching health data for astronauts."""
20
- return {
21
- "Heart Rate (bpm)": np.random.randint(50, 120),
22
- "Oxygen Saturation (%)": np.random.randint(80, 100),
23
- "Stress Indicator": np.random.choice(["Low", "Moderate", "High"])
24
- }
25
-
26
- def fetch_resource_data():
27
- """Simulate fetching resource data."""
28
- return {key: np.random.uniform(*limits) for key, limits in RESOURCE_LIMITS.items()}
 
 
 
 
 
 
 
29
 
30
- def groq_predict_alert(message):
31
- """Use Groq API to analyze emergency alerts."""
32
- try:
33
- result = client.predict({"text": message})
34
- return result.get("label", "No label detected")
35
- except Exception as e:
36
- return f"Error using Groq API: {e}"
37
 
38
- # Streamlit UI
39
- st.title("ARMS: Autonomous Resource Management System")
40
- st.write("Track, analyze, and optimize survival resources for space missions.")
 
41
 
42
- st.subheader("Real-Time Monitoring")
43
- resource_data = fetch_resource_data()
44
- health_data = fetch_health_data()
 
 
 
 
 
 
 
 
 
45
 
46
- col1, col2 = st.columns(2)
47
- with col1:
48
- st.write("### Resource Metrics")
49
- for key, value in resource_data.items():
50
- st.metric(key, f"{value:.2f}")
 
51
 
52
- with col2:
53
- st.write("### Astronaut Health Metrics")
54
- for key, value in health_data.items():
55
- st.metric(key, value)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- # Predictive Analytics
58
- st.subheader("Predictive Analysis & Alerts")
59
- if st.button("Run Groq Analysis"):
60
- alert_message = "Critical alert: Resources dangerously low. Immediate action required!"
61
- groq_result = groq_predict_alert(alert_message)
62
- st.write("Groq API Result:", groq_result)
63
- st.warning(alert_message)
64
 
65
- st.write("Developed for Hackathon using Groq API, Streamlit, and Hugging Face.")
 
 
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.")