Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,77 +1,114 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
from catboost import CatBoostRegressor
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# Specialization: restricted choices.
|
| 20 |
-
specializations = [
|
| 21 |
-
'electronics & instrumentation',
|
| 22 |
-
'computer science',
|
| 23 |
-
'electronics & communication',
|
| 24 |
-
'biotechnology',
|
| 25 |
-
'mechanical',
|
| 26 |
-
'information technology',
|
| 27 |
-
'electrical engineering',
|
| 28 |
-
'electronics and electrical engineering',
|
| 29 |
-
'information science engineering',
|
| 30 |
-
'chemical engineering',
|
| 31 |
-
'ceramic engineering',
|
| 32 |
-
'metallurgical engineering',
|
| 33 |
-
'aeronautical engineering',
|
| 34 |
-
'electronics engineering',
|
| 35 |
-
'civil engineering',
|
| 36 |
-
'industrial & production engineering',
|
| 37 |
-
'other',
|
| 38 |
-
'electronics and computer engineering',
|
| 39 |
-
'industrial & management engineering',
|
| 40 |
-
'biomedical engineering',
|
| 41 |
-
'computer application',
|
| 42 |
-
'electrical and power engineering',
|
| 43 |
-
'industrial engineering',
|
| 44 |
-
'mechatronics',
|
| 45 |
-
'information & communication technology'
|
| 46 |
-
]
|
| 47 |
-
specialization = st.selectbox("Specialization", specializations)
|
| 48 |
-
|
| 49 |
-
# CGPA: user inputs on 0-10 scale, then scale up to 100.
|
| 50 |
-
cgpa_input = st.number_input("College GPA (0-10 scale)", min_value=0.0, max_value=10.0, value=7.5)
|
| 51 |
-
college_gpa = cgpa_input * 10
|
| 52 |
-
|
| 53 |
-
# Location: accepted values.
|
| 54 |
-
locations = [
|
| 55 |
-
"Delhi", "Uttar Pradesh", "Maharashtra", "Tamil Nadu", "West Bengal", "Telangana",
|
| 56 |
-
"Andhra Pradesh", "Haryana", "Karnataka", "Orissa", "Chhattisgarh", "Rajasthan",
|
| 57 |
-
"Punjab", "Madhya Pradesh", "Uttarakhand", "Gujarat", "Jharkhand", "Himachal Pradesh",
|
| 58 |
-
"Bihar", "Kerala", "Assam", "Jammu and Kashmir", "Sikkim", "Meghalaya", "Goa"
|
| 59 |
-
]
|
| 60 |
-
location = st.selectbox("Location", locations)
|
| 61 |
-
|
| 62 |
-
# Build the input DataFrame with columns expected by the model.
|
| 63 |
-
input_df = pd.DataFrame({
|
| 64 |
-
"Gender": [gender],
|
| 65 |
-
"10percentage": [perc_10],
|
| 66 |
-
"12percentage": [perc_12],
|
| 67 |
-
"CollegeTier": [tier],
|
| 68 |
-
"Specialization": [specialization],
|
| 69 |
-
"collegeGPA": [college_gpa],
|
| 70 |
-
"CollegeState": [location] # mapping 'Location' to model's 'CollegeState'
|
| 71 |
-
})
|
| 72 |
-
|
| 73 |
-
if st.button("Predict Salary"):
|
| 74 |
-
prediction = model.predict(input_df)
|
| 75 |
-
st.success(f"Predicted Salary: {prediction[0]:.2f}")
|
| 76 |
-
|
| 77 |
-
# To run, save this file (e.g., app.py) and execute 'streamlit run app.py'
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import sqlite3
|
| 4 |
from catboost import CatBoostRegressor
|
| 5 |
|
| 6 |
+
def predict_mode():
|
| 7 |
+
st.title("📊 Predict Mode: Salary Prediction")
|
| 8 |
+
|
| 9 |
+
# Input fields
|
| 10 |
+
gender = st.selectbox("Gender", ["m", "f"])
|
| 11 |
+
perc_10 = st.number_input("10th Percentage", min_value=0.0, max_value=100.0, value=80.0)
|
| 12 |
+
perc_12 = st.number_input("12th Percentage", min_value=0.0, max_value=100.0, value=80.0)
|
| 13 |
+
|
| 14 |
+
tier = st.selectbox("College Tier (Only 1 or 2 accepted)", [1, 2])
|
| 15 |
+
|
| 16 |
+
specializations = [
|
| 17 |
+
'electronics & instrumentation',
|
| 18 |
+
'computer science',
|
| 19 |
+
'electronics & communication',
|
| 20 |
+
'biotechnology',
|
| 21 |
+
'mechanical',
|
| 22 |
+
'information technology',
|
| 23 |
+
'electrical engineering',
|
| 24 |
+
'electronics and electrical engineering',
|
| 25 |
+
'information science engineering',
|
| 26 |
+
'chemical engineering',
|
| 27 |
+
'ceramic engineering',
|
| 28 |
+
'metallurgical engineering',
|
| 29 |
+
'aeronautical engineering',
|
| 30 |
+
'electronics engineering',
|
| 31 |
+
'civil engineering',
|
| 32 |
+
'industrial & production engineering',
|
| 33 |
+
'other',
|
| 34 |
+
'electronics and computer engineering',
|
| 35 |
+
'industrial & management engineering',
|
| 36 |
+
'biomedical engineering',
|
| 37 |
+
'computer application',
|
| 38 |
+
'electrical and power engineering',
|
| 39 |
+
'industrial engineering',
|
| 40 |
+
'mechatronics',
|
| 41 |
+
'information & communication technology'
|
| 42 |
+
]
|
| 43 |
+
specialization = st.selectbox("Specialization", specializations)
|
| 44 |
+
|
| 45 |
+
cgpa_input = st.number_input("College GPA (0-10 scale)", min_value=0.0, max_value=10.0, value=7.5)
|
| 46 |
+
college_gpa = cgpa_input * 10 # Scale up to 100
|
| 47 |
+
|
| 48 |
+
locations = [
|
| 49 |
+
"Delhi", "Uttar Pradesh", "Maharashtra", "Tamil Nadu", "West Bengal", "Telangana",
|
| 50 |
+
"Andhra Pradesh", "Haryana", "Karnataka", "Orissa", "Chhattisgarh", "Rajasthan",
|
| 51 |
+
"Punjab", "Madhya Pradesh", "Uttarakhand", "Gujarat", "Jharkhand", "Himachal Pradesh",
|
| 52 |
+
"Bihar", "Kerala", "Assam", "Jammu and Kashmir", "Sikkim", "Meghalaya", "Goa"
|
| 53 |
+
]
|
| 54 |
+
location = st.selectbox("Location", locations)
|
| 55 |
+
|
| 56 |
+
# Prepare input DataFrame for prediction
|
| 57 |
+
input_df = pd.DataFrame({
|
| 58 |
+
"Gender": [gender],
|
| 59 |
+
"10percentage": [perc_10],
|
| 60 |
+
"12percentage": [perc_12],
|
| 61 |
+
"CollegeTier": [tier],
|
| 62 |
+
"Specialization": [specialization],
|
| 63 |
+
"collegeGPA": [college_gpa],
|
| 64 |
+
"CollegeState": [location]
|
| 65 |
+
})
|
| 66 |
+
|
| 67 |
+
if st.button("Predict Salary"):
|
| 68 |
+
model = CatBoostRegressor()
|
| 69 |
+
model.load_model("PlaceMe_CatBoost.cbm", format="cbm")
|
| 70 |
+
prediction = model.predict(input_df)
|
| 71 |
+
st.success(f"Predicted Salary: {prediction[0]:.2f}")
|
| 72 |
|
| 73 |
+
def db_mode():
|
| 74 |
+
st.title("🗄️ DB Mode: Database Viewer")
|
| 75 |
+
|
| 76 |
+
# Connect to SQLite database.
|
| 77 |
+
conn = sqlite3.connect("PlaceMeNot.db")
|
| 78 |
+
|
| 79 |
+
# Get table names from the database
|
| 80 |
+
table_query = "SELECT name FROM sqlite_master WHERE type='table';"
|
| 81 |
+
tables = pd.read_sql(table_query, conn)
|
| 82 |
+
|
| 83 |
+
if tables.empty:
|
| 84 |
+
st.error("No tables found in the database.")
|
| 85 |
+
return
|
| 86 |
+
else:
|
| 87 |
+
# Assuming we use the first available table.
|
| 88 |
+
table_name = tables.iloc[0, 0]
|
| 89 |
+
st.write(f"Using table: **{table_name}**")
|
| 90 |
+
|
| 91 |
+
# Allow user to sort data
|
| 92 |
+
cols = ["Gender", "10percentage", "12percentage", "CollegeTier",
|
| 93 |
+
"Specialization", "collegeGPA", "CollegeState", "Salary"]
|
| 94 |
+
sort_col = st.selectbox("Sort by", cols)
|
| 95 |
+
order = st.radio("Order", ("Ascending", "Descending"))
|
| 96 |
+
order_str = "ASC" if order == "Ascending" else "DESC"
|
| 97 |
+
|
| 98 |
+
query = f"SELECT * FROM {table_name} ORDER BY {sort_col} {order_str}"
|
| 99 |
+
df = pd.read_sql(query, conn)
|
| 100 |
+
st.dataframe(df)
|
| 101 |
+
|
| 102 |
+
conn.close()
|
| 103 |
|
| 104 |
+
def main():
|
| 105 |
+
st.sidebar.title("Mode Selection")
|
| 106 |
+
mode = st.sidebar.radio("Choose Mode", ["Predict Mode", "DB Mode"])
|
| 107 |
+
|
| 108 |
+
if mode == "Predict Mode":
|
| 109 |
+
predict_mode()
|
| 110 |
+
else:
|
| 111 |
+
db_mode()
|
| 112 |
|
| 113 |
+
if __name__ == '__main__':
|
| 114 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|