Spaces:
Build error
Build error
updated
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from sklearn.model_selection import train_test_split
|
|
| 5 |
from sklearn.preprocessing import LabelEncoder
|
| 6 |
from sklearn.ensemble import RandomForestClassifier
|
| 7 |
import joblib
|
|
|
|
| 8 |
|
| 9 |
# Load and preprocess data
|
| 10 |
def load_and_preprocess_data(filename):
|
|
@@ -38,8 +39,8 @@ joblib.dump(label_encoders, "label_encoders.pkl")
|
|
| 38 |
|
| 39 |
# Prediction function
|
| 40 |
def predict_colleges(category, gender, rank, region):
|
| 41 |
-
if not isinstance(rank, (int, float)) or rank < 0:
|
| 42 |
-
return "Invalid Rank: Please enter a valid positive
|
| 43 |
|
| 44 |
# Load label encoders
|
| 45 |
label_encoders = joblib.load("label_encoders.pkl")
|
|
@@ -77,7 +78,7 @@ demo = gr.Interface(
|
|
| 77 |
inputs=[
|
| 78 |
gr.Dropdown(choices=["OC", "BC", "SC", "ST"], label="Category"),
|
| 79 |
gr.Radio(choices=["Male", "Female"], label="Gender"),
|
| 80 |
-
gr.
|
| 81 |
gr.Dropdown(choices=["AU", "SV"], label="Region")
|
| 82 |
],
|
| 83 |
outputs=gr.Dataframe(headers=["College Name", "Branch"]),
|
|
@@ -85,4 +86,4 @@ demo = gr.Interface(
|
|
| 85 |
description="Enter your details to predict all possible colleges and branches based on your rank."
|
| 86 |
)
|
| 87 |
|
| 88 |
-
demo.launch()
|
|
|
|
| 5 |
from sklearn.preprocessing import LabelEncoder
|
| 6 |
from sklearn.ensemble import RandomForestClassifier
|
| 7 |
import joblib
|
| 8 |
+
import re
|
| 9 |
|
| 10 |
# Load and preprocess data
|
| 11 |
def load_and_preprocess_data(filename):
|
|
|
|
| 39 |
|
| 40 |
# Prediction function
|
| 41 |
def predict_colleges(category, gender, rank, region):
|
| 42 |
+
if not isinstance(rank, (int, float)) or rank < 0 or not re.match(r'^\d+$', str(rank)):
|
| 43 |
+
return "Invalid Rank: Please enter a valid positive integer without symbols."
|
| 44 |
|
| 45 |
# Load label encoders
|
| 46 |
label_encoders = joblib.load("label_encoders.pkl")
|
|
|
|
| 78 |
inputs=[
|
| 79 |
gr.Dropdown(choices=["OC", "BC", "SC", "ST"], label="Category"),
|
| 80 |
gr.Radio(choices=["Male", "Female"], label="Gender"),
|
| 81 |
+
gr.Textbox(label="Rank", type="number"), # Restrict to number input
|
| 82 |
gr.Dropdown(choices=["AU", "SV"], label="Region")
|
| 83 |
],
|
| 84 |
outputs=gr.Dataframe(headers=["College Name", "Branch"]),
|
|
|
|
| 86 |
description="Enter your details to predict all possible colleges and branches based on your rank."
|
| 87 |
)
|
| 88 |
|
| 89 |
+
demo.launch()
|