File size: 5,300 Bytes
682b5ba
 
34448fe
682b5ba
 
34448fe
8ad0045
34448fe
 
055dde9
817c11b
 
 
 
34448fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
817c11b
34448fe
817c11b
34448fe
 
 
 
 
 
 
 
817c11b
34448fe
055dde9
34448fe
 
 
 
 
 
 
 
 
 
 
 
 
 
8ad0045
682b5ba
34448fe
8ad0045
34448fe
 
055dde9
34448fe
 
 
 
 
 
 
 
055dde9
34448fe
 
 
 
 
055dde9
 
 
 
 
34448fe
 
 
 
055dde9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34448fe
 
682b5ba
34448fe
 
 
 
 
 
 
 
682b5ba
34448fe
 
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import streamlit as st
import pandas as pd
import sqlite3
from catboost import CatBoostRegressor

def predict_mode():
    st.title("πŸ…ΏπŸ…»πŸ…°πŸ…²πŸ…΄ πŸ„ΌπŸ„΄")
    st.title("πŸ“Š Predict Mode: Salary Prediction")
    
    # Input fields for prediction
    gender = st.selectbox("Gender 🚻", ["m", "f"])
    perc_10 = st.number_input("10th Percentage β‘©", min_value=0.0, max_value=100.0, value=80.0)
    perc_12 = st.number_input("12th Percentage β‘«", min_value=0.0, max_value=100.0, value=80.0)
    tier = st.selectbox("College Tier (Only 1 or 2 accepted) πŸ›οΈ", [1, 2])
    
    specializations = [
        'electronics & instrumentation',
        'computer science',
        'electronics & communication',
        'biotechnology',
        'mechanical',
        'information technology',
        'electrical engineering',
        'electronics and electrical engineering',
        'information science engineering',
        'chemical engineering',
        'ceramic engineering',
        'metallurgical engineering',
        'aeronautical engineering',
        'electronics engineering',
        'civil engineering',
        'industrial & production engineering',
        'other',
        'electronics and computer engineering',
        'industrial & management engineering',
        'biomedical engineering',
        'computer application',
        'electrical and power engineering',
        'industrial engineering',
        'mechatronics',
        'information & communication technology'
    ]
    specialization = st.selectbox("Specialization βš™οΈ", specializations)
    
    cgpa_input = st.number_input("College GPA (0-10 scale πŸ“)", min_value=0.0, max_value=10.0, value=7.5)
    college_gpa = cgpa_input * 10  # Scale up to 100
    
    locations = [
        "Delhi", "Uttar Pradesh", "Maharashtra", "Tamil Nadu", "West Bengal", "Telangana",
        "Andhra Pradesh", "Haryana", "Karnataka", "Orissa", "Chhattisgarh", "Rajasthan", 
        "Punjab", "Madhya Pradesh", "Uttarakhand", "Gujarat", "Jharkhand", "Himachal Pradesh", 
        "Bihar", "Kerala", "Assam", "Jammu and Kashmir", "Sikkim", "Meghalaya", "Goa"
    ]
    location = st.selectbox("Location πŸ“", locations)
    
    # Prepare input DataFrame (ensure column names match training data)
    input_df = pd.DataFrame({
        "Gender": [gender],
        "10percentage": [perc_10],
        "12percentage": [perc_12],
        "CollegeTier": [tier],
        "Specialization": [specialization],
        "collegeGPA": [college_gpa],
        "CollegeState": [location]
    })
    
    if st.button("Predict Salary"):
        model = CatBoostRegressor()
        model.load_model("PlaceMe_CatBoost.cbm", format="cbm")
        prediction = model.predict(input_df)
        st.success(f"Predicted Salary: β‚Ή{prediction[0]:.2f}")

def db_mode():
    st.title("πŸ…ΏπŸ…»πŸ…°πŸ…²πŸ…΄ πŸ„ΌπŸ„΄")
    st.title("πŸ—„οΈ DB Mode: Database Viewer")
    
    # Connect to the SQLite database
    conn = sqlite3.connect("PlaceMeNot.db")
    table_query = "SELECT name FROM sqlite_master WHERE type='table';"
    tables = pd.read_sql(table_query, conn)
    
    if tables.empty:
        st.error("No tables found in the database.")
        return
    else:
        # Use first available table (you can extend this to allow user selection)
        table_name = tables.iloc[0, 0]
        st.write(f"Using table: **{table_name}**")
    
    cols = ["Gender", "10percentage", "12percentage", "CollegeTier", 
            "Specialization", "collegeGPA", "CollegeState", "Salary"]
    
    # Option to select which columns to display
    selected_cols = st.multiselect("Select columns to display", options=cols, default=cols)
    
    # Sorting feature: note the need to quote columns with numeric names.
    sort_col = st.selectbox("Sort by", cols)
    order = st.radio("Order", ("Ascending", "Descending"))
    order_str = "ASC" if order == "Ascending" else "DESC"
    
    # Filtering feature
    st.subheader("Filtering")
    filter_col = st.selectbox("Filter column", cols)
    filter_value = st.text_input("Filter value (exact match, leave empty for no filter)")
    
    numeric_cols = ["10percentage", "12percentage", "CollegeTier", "collegeGPA", "Salary"]
    filter_clause = ""
    if filter_value:
        if filter_col in numeric_cols:
            filter_clause = f'WHERE "{filter_col}" = {filter_value}'
        else:
            filter_clause = f'WHERE "{filter_col}" = "{filter_value}"'
    
    # Build the query using double quotes for column names
    col_str = ", ".join([f'"{col}"' for col in selected_cols])
    query = f'SELECT {col_str} FROM "{table_name}" {filter_clause} ORDER BY "{sort_col}" {order_str}'
    
    st.write("Executing query:")
    st.code(query, language="sql")
    
    try:
        df = pd.read_sql(query, conn)
        st.dataframe(df)
        
        st.subheader("Summary Statistics")
        if not df.empty:
            st.write(df.describe())
    except Exception as e:
        st.error(f"Error executing query: {e}")
    
    conn.close()

def main():
    st.sidebar.title("Mode Selection")
    mode = st.sidebar.radio("Choose Mode", ["Predict Mode", "DB Mode"])
    
    if mode == "Predict Mode":
        predict_mode()
    else:
        db_mode()

if __name__ == '__main__':
    main()