Spaces:
Build error
Build error
| 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() | |