Ci-Dave's picture
removed sklearn as import
40b5a6f
# Pokemon Explorer is an interactive Streamlit app for exploring Pokémon data!
# Easily browse Pokémon stats, visualize and predict attributes, and filter by type or name.
import streamlit as st
import pandas as pd
import joblib
import matplotlib.pyplot as plt
import seaborn as sns
import os
print(os.getcwd())
# Load dataset
@st.cache_data
def load_data():
file_path = "pokemon_cleaned.csv"
if not os.path.exists(file_path):
st.error(f"❌ File not found: {file_path}")
return None # Return None if file doesn't exist
try:
df = pd.read_csv(file_path)
return df
except Exception as e:
st.error(f"❌ Failed to load the CSV: {e}")
return None # Return None in case of an error
df = load_data()
if df is None:
st.stop()
# Load machine learning models for prediction
model = joblib.load("random_forest.pkl")
model = joblib.load("logistic_regression.pkl")
model = joblib.load("naive_bayes.pkl")
# Sidebar Navigation
st.sidebar.title("🔍 Pokémon Explorer")
st.sidebar.markdown("Navigate through different sections!")
page = st.sidebar.radio(" Select a Page", ["Home", "Data Overview", "Visualization and Prediction"])
# Home Page
if page == "Home":
st.title("Pokémon Explorer")
st.markdown("Explore Pokémon stats, types, and visualizations interactively! ")
st.markdown("### Features:")
st.write("✔️ Browse Pokémon data")
st.write("✔️ Visualize Pokémon stats")
st.write("✔️ Search and filter Pokémon")
st.write("✔️ Predict Pokémon attributes")
# Data Overview Page
elif page == "Data Overview":
st.title("Pokémon Data Overview")
st.write("Browse and explore the Pokémon dataset.")
name_search = st.text_input("🔍 Search Pokémon by Name")
type_filter = st.selectbox("🎨 Filter by Type", ["All"] + sorted(df['Type 1'].unique().tolist()))
filtered_df = df
if name_search:
filtered_df = filtered_df[filtered_df['Name'].str.contains(name_search, case=False, na=False)]
if type_filter != "All":
filtered_df = filtered_df[filtered_df['Type 1'] == type_filter]
st.dataframe(filtered_df, use_container_width=True)
# Visualization and Prediction Page
elif page == "Visualization and Prediction":
st.title(" Pokémon Data Visualization and Prediction")
st.write("Explore Pokémon stats with interactive graphs!")
pokemon_list = df['Name'].unique().tolist()
selected_pokemon_name = st.selectbox("🔍 Select a Pokémon", pokemon_list)
selected_pokemon = df[df['Name'] == selected_pokemon_name]
if not selected_pokemon.empty:
st.write(f"### {selected_pokemon.iloc[0]['Name']}")
st.write(f"**Type:** {selected_pokemon.iloc[0]['Type 1']} / {selected_pokemon.iloc[0].get('Type 2', 'None')}")
st.write(f"**Legendary:** {'Yes' if selected_pokemon.iloc[0]['Legendary'] else 'No'}")
st.write(f"**Generation:** {selected_pokemon.iloc[0]['Generation']}")
stats = ["HP", "Attack", "Defense", "Speed"]
fig, ax = plt.subplots(figsize=(8, 5))
sns.barplot(x=stats, y=selected_pokemon.iloc[0][stats].values, ax=ax)
ax.set_xlabel("Stats")
ax.set_ylabel("Value")
ax.set_title(f"Stat Distribution for {selected_pokemon.iloc[0]['Name']}")
st.pyplot(fig)
st.sidebar.markdown("---")
st.sidebar.write("✨ Made by CI-DAVE")