Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,10 @@ from catboost import CatBoostRegressor
|
|
| 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 = [
|
|
@@ -53,7 +52,7 @@ def predict_mode():
|
|
| 53 |
]
|
| 54 |
location = st.selectbox("Location", locations)
|
| 55 |
|
| 56 |
-
# Prepare input DataFrame
|
| 57 |
input_df = pd.DataFrame({
|
| 58 |
"Gender": [gender],
|
| 59 |
"10percentage": [perc_10],
|
|
@@ -73,10 +72,8 @@ def predict_mode():
|
|
| 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 |
|
|
@@ -84,20 +81,50 @@ def db_mode():
|
|
| 84 |
st.error("No tables found in the database.")
|
| 85 |
return
|
| 86 |
else:
|
| 87 |
-
#
|
| 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 |
-
|
| 99 |
-
|
| 100 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
conn.close()
|
| 103 |
|
|
|
|
| 6 |
def predict_mode():
|
| 7 |
st.title("๐ Predict Mode: Salary Prediction")
|
| 8 |
|
| 9 |
+
# Input fields for prediction
|
| 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 |
tier = st.selectbox("College Tier (Only 1 or 2 accepted)", [1, 2])
|
| 14 |
|
| 15 |
specializations = [
|
|
|
|
| 52 |
]
|
| 53 |
location = st.selectbox("Location", locations)
|
| 54 |
|
| 55 |
+
# Prepare input DataFrame (ensure column names match training data)
|
| 56 |
input_df = pd.DataFrame({
|
| 57 |
"Gender": [gender],
|
| 58 |
"10percentage": [perc_10],
|
|
|
|
| 72 |
def db_mode():
|
| 73 |
st.title("๐๏ธ DB Mode: Database Viewer")
|
| 74 |
|
| 75 |
+
# Connect to the SQLite database
|
| 76 |
conn = sqlite3.connect("PlaceMeNot.db")
|
|
|
|
|
|
|
| 77 |
table_query = "SELECT name FROM sqlite_master WHERE type='table';"
|
| 78 |
tables = pd.read_sql(table_query, conn)
|
| 79 |
|
|
|
|
| 81 |
st.error("No tables found in the database.")
|
| 82 |
return
|
| 83 |
else:
|
| 84 |
+
# Use first available table (you can extend this to allow user selection)
|
| 85 |
table_name = tables.iloc[0, 0]
|
| 86 |
st.write(f"Using table: **{table_name}**")
|
| 87 |
|
|
|
|
| 88 |
cols = ["Gender", "10percentage", "12percentage", "CollegeTier",
|
| 89 |
"Specialization", "collegeGPA", "CollegeState", "Salary"]
|
| 90 |
+
|
| 91 |
+
# Option to select which columns to display
|
| 92 |
+
selected_cols = st.multiselect("Select columns to display", options=cols, default=cols)
|
| 93 |
+
|
| 94 |
+
# Sorting feature: note the need to quote columns with numeric names.
|
| 95 |
sort_col = st.selectbox("Sort by", cols)
|
| 96 |
order = st.radio("Order", ("Ascending", "Descending"))
|
| 97 |
order_str = "ASC" if order == "Ascending" else "DESC"
|
| 98 |
|
| 99 |
+
# Filtering feature
|
| 100 |
+
st.subheader("Filtering")
|
| 101 |
+
filter_col = st.selectbox("Filter column", cols)
|
| 102 |
+
filter_value = st.text_input("Filter value (exact match, leave empty for no filter)")
|
| 103 |
+
|
| 104 |
+
numeric_cols = ["10percentage", "12percentage", "CollegeTier", "collegeGPA", "Salary"]
|
| 105 |
+
filter_clause = ""
|
| 106 |
+
if filter_value:
|
| 107 |
+
if filter_col in numeric_cols:
|
| 108 |
+
filter_clause = f'WHERE "{filter_col}" = {filter_value}'
|
| 109 |
+
else:
|
| 110 |
+
filter_clause = f'WHERE "{filter_col}" = "{filter_value}"'
|
| 111 |
+
|
| 112 |
+
# Build the query using double quotes for column names
|
| 113 |
+
col_str = ", ".join([f'"{col}"' for col in selected_cols])
|
| 114 |
+
query = f'SELECT {col_str} FROM "{table_name}" {filter_clause} ORDER BY "{sort_col}" {order_str}'
|
| 115 |
+
|
| 116 |
+
st.write("Executing query:")
|
| 117 |
+
st.code(query, language="sql")
|
| 118 |
+
|
| 119 |
+
try:
|
| 120 |
+
df = pd.read_sql(query, conn)
|
| 121 |
+
st.dataframe(df)
|
| 122 |
+
|
| 123 |
+
st.subheader("Summary Statistics")
|
| 124 |
+
if not df.empty:
|
| 125 |
+
st.write(df.describe())
|
| 126 |
+
except Exception as e:
|
| 127 |
+
st.error(f"Error executing query: {e}")
|
| 128 |
|
| 129 |
conn.close()
|
| 130 |
|