Skip to content

Commit

Permalink
Enhanced streamlit userinterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Akanshaku committed Oct 19, 2024
1 parent 17b4c27 commit 511e0ed
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 11 deletions.
98 changes: 95 additions & 3 deletions Home.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import streamlit as st
import pandas as pd
import time
import plotly.express as px

# Configure the page with a modern theme and a custom icon
st.set_page_config(
Expand All @@ -7,10 +10,26 @@
layout="wide",
initial_sidebar_state="expanded",
)
# Adding selectboxes for user customization


# Sidebar content with advanced layout

st.markdown(
"""
<style>
.stApp {
background-color: #0F0F0F;
color: #FFFFFF;
}
.sidebar .sidebar-content {
background: linear-gradient(45deg, #141E30, #243B55);
color: white;
}
</style>
""",
unsafe_allow_html=True
)
# Sidebar content with user customization options
with st.sidebar:
mining_importance = st.selectbox(
"🔧 **Select Mining Site Importance Level**",
Expand All @@ -20,9 +39,14 @@
"🌐 **Filter Sites by Distance**",
options=["< 100 light years", "100-500 light years", "500-1000 light years", "> 1000 light years"]
)
outlier_sensitivity = st.selectbox(
outlier_sensitivity = st.slider(
"🔍 **Adjust Sensitivity for Outlier Detection**",
options=["Low", "Medium", "High"]
min_value=0, max_value=100, value=50
)
mining_site_types = st.multiselect(
"🏔️ **Select Mining Site Types**",
options=["Asteroid", "Moon", "Planet", "Comet"],
default=["Asteroid", "Planet"]
)
st.title("🪐 **Galactic Mining Hub**")
st.subheader("Deep dive into the infinite cosmic sea!")
Expand Down Expand Up @@ -73,6 +97,74 @@
unsafe_allow_html=True
)

tab1, tab2, tab3 = st.tabs(["Overview", "Prediction Model", "Visualizations"])

with tab1:
st.markdown(
"""
<div style="text-align: center; margin-top: 50px;">
<h1>🛰️ <strong>Galactic Mining Hub</strong></h1>
<h2><em>Explore, Analyze, and Discover Cosmic Mining Sites with Advanced AI</em></h2>
</div>
""",
unsafe_allow_html=True
)
st.divider()
st.markdown(
"""
**Welcome to the Galactic Mining Hub**, where Machine Learning meets space exploration!
"""
)

with tab2:
st.header("🚀 Prediction Model")
st.markdown("Engage with predictive analysis to identify the best mining sites.")
if st.button("Run Prediction Model"):
with st.spinner("Running the model, please wait..."):
time.sleep(2) # Simulate a long-running task
st.success("Model prediction completed!")

# Sample results for demonstration purposes
results_df = pd.DataFrame({
'Mining Site': ['Site A', 'Site B', 'Site C'],
'Predicted Value': [0.85, 0.78, 0.92]
})
st.write(results_df)

# Button to download the DataFrame as CSV
csv = results_df.to_csv(index=False).encode('utf-8')
st.download_button(
label="📥 Download Results as CSV",
data=csv,
file_name='mining_site_predictions.csv',
mime='text/csv'
)

with tab3:
st.header("📈 Cutting-Edge Visualizations")
st.markdown("Explore the data through a range of interactive visualizations.")

# Sample data for visualization
data = pd.DataFrame({
'Distance (light years)': [50, 150, 300, 750, 1200],
'Mining Importance': ['Low', 'Medium', 'High', 'Critical', 'Medium'],
'Feasibility Score': [0.2, 0.6, 0.8, 0.95, 0.5]
})

# Interactive scatter plot using Plotly
fig = px.scatter(
data,
x='Distance (light years)',
y='Feasibility Score',
color='Mining Importance',
title="Mining Site Feasibility Analysis",
labels={"Feasibility Score": "Feasibility", "Distance (light years)": "Distance"}
)
st.plotly_chart(fig)

# Footer
st.markdown("---")
st.markdown("**Ready to embark on your cosmic journey?** Use the sidebar to navigate through the hub’s capabilities and start your exploration!")
st.divider()

# Information and interactive section
Expand Down
33 changes: 25 additions & 8 deletions visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@
import matplotlib.pyplot as plt
import seaborn as sns

# Set the title and icon of the Streamlit page
st.set_page_config(page_title="Mining Site Visualization", page_icon="🔍")

def load_data():
# Load the dataset
data = pd.read_csv("space_mining_dataset.csv")
return data

#Load the dataset from CSV and handle errors if the file is not found.
try:
data = pd.read_csv("space_mining_dataset.csv")
return data
except FileNotFoundError:
st.error("Dataset file not found. Please upload the correct file.")
return pd.DataFrame()

def show_visualize_page():
#Main function to show the visualization page.
st.title("Mining Site Visualization")
st.write("Explore different visualizations to understand the dataset and the impact of user preferences.")

data = load_data()
if data.empty:
return

# Check available columns in the dataset
st.write("Available Columns:", data.columns)

required_columns = ['iron', 'nickel', 'water_ice', 'other_minerals', 'sustainability_index', 'distance_from_earth']
if not all(col in data.columns for col in required_columns):
st.error(f"Dataset must contain the following columns: {', '.join(required_columns)}")
return

# If 'final_score' does not exist, calculate it based on other features
if 'final_score' not in data.columns:
st.write("The 'final_score' column does not exist, calculating it based on weights.")
Expand Down Expand Up @@ -52,16 +65,20 @@ def show_visualize_page():
# Use a more colorful palette for the histogram
sns.histplot(data[feature], bins=20, kde=True, ax=ax, color='teal')
ax.set_xlabel(feature)
ax.set_title(f"Distribution of {feature}")
st.pyplot(fig)

# Visualization 2: Pairplot of Selected Features
st.subheader("Pairplot of Selected Features")
features = st.multiselect("Select Features for Pairplot", data.columns[1:]) # Exclude non-numeric columns if necessary
if len(features) > 1:
fig, ax = plt.subplots()
if len(features) > 4:
st.warning("Select up to 4 features for pairplot for better performance.")
else:
fig, ax = plt.subplots()

# Customizing pairplot with a color palette
pairplot_fig = sns.pairplot(data[features + ['final_score']], diag_kind='kde', hue='final_score', palette="coolwarm")
spairplot_fig = sns.pairplot(data[features + ['final_score']], diag_kind='kde', hue='final_score', palette="coolwarm")
st.pyplot(pairplot_fig.fig)
else:
st.write("Please select more than one feature.")
Expand All @@ -73,9 +90,9 @@ def show_visualize_page():
corr_matrix = numeric_data.corr()

# Displaying the heatmap
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=(10, 8))
sns.heatmap(corr_matrix, annot=True, fmt=".2f", cmap="coolwarm", linewidths=0.5, ax=ax)
ax.set_title("Correlation Heatmap")
ax.set_title("Correlation Heatmap", fontsize=16)
st.pyplot(fig)

# Visualization 4: Boxplot of Feature Distribution by Category
Expand Down

0 comments on commit 511e0ed

Please sign in to comment.