File size: 3,428 Bytes
cd5b21c
 
 
 
 
 
 
 
d7e381c
40b5a6f
cd5b21c
d7e381c
94249b2
cd5b21c
 
 
94249b2
 
 
 
 
 
 
 
 
 
 
 
cd5b21c
 
 
94249b2
 
 
2256fe9
887ad5e
 
 
cd5b21c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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")