File size: 2,300 Bytes
38ee179
5a03aa6
e1538aa
38ee179
5a03aa6
ecf1cf1
38ee179
 
5a03aa6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
import pandas as pd
from groq import Groq

# Initialize the Groq API
GROQ_API_KEY = "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"
client = Groq(api_key=GROQ_API_KEY)

# Load CSV dataset
st.title("🚀 Mission Analytics & Recommendations")
uploaded_file = st.file_uploader("Upload your dataset (CSV format)", type="csv")

if uploaded_file:
    # Read the uploaded CSV
    data = pd.read_csv(uploaded_file)
    st.write("### Dataset Overview", data.head())

    # Select Mission ID
    mission_id = st.selectbox("Select a Mission ID for Prediction and Recommendation", data["Mission ID"].unique())
    
    # Display mission information
    if mission_id:
        mission_data = data[data["Mission ID"] == mission_id].iloc[0]
        st.subheader(f"Mission Details: {mission_id}")
        st.write(mission_data)

        # API call function for prediction and recommendation
        def fetch_recommendation(mission_details):
            """Fetch recommendations based on mission data."""
            content = (
                f"Given this mission data: "
                f"Name: {mission_details['Mission Name']}, "
                f"Target Type: {mission_details['Target Type']}, "
                f"Distance: {mission_details['Distance from Earth (light-years)']} light-years, "
                f"Cost: {mission_details['Mission Cost (billion USD)']} billion USD, "
                f"Success Rate: {mission_details['Mission Success (%)']}%, "
                f"Provide insights and suggestions for optimization."
            )

            try:
                response = client.chat.completions.create(
                    messages=[{"role": "user", "content": content}],
                    model="llama-3.3-70b-versatile",
                )
                return response.choices[0].message.content
            except Exception as e:
                return f"Error fetching prediction: {e}"

        # Fetch and display prediction/recommendation
        if st.button("Get Prediction and Recommendations"):
            st.text("Fetching insights from Groq API...")
            result = fetch_recommendation(mission_data)
            st.write("### Recommendations")
            st.success(result)

else:
    st.warning("Please upload a CSV file to proceed.")