Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,17 @@ mapping = {
|
|
| 19 |
|
| 20 |
# Define the function for making predictions
|
| 21 |
def salarybracket(age, workclass, education, marital_status, occupation, relationship, race, gender, native_country):
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
prediction = model.predict(inputs)
|
| 24 |
prediction_value = prediction[0][0] # Assuming the prediction is a scalar
|
| 25 |
result = "Income_bracket lesser than or equal to 50K ⬇️" if prediction_value <= 0.5 else "Income_bracket greater than 50K ⬆️"
|
|
@@ -30,7 +40,7 @@ dropdown_options = {}
|
|
| 30 |
for column, values in mapping.items():
|
| 31 |
options = []
|
| 32 |
for label, value in values.items():
|
| 33 |
-
options.append(
|
| 34 |
dropdown_options[column] = options
|
| 35 |
|
| 36 |
# Create the Gradio interface
|
|
@@ -52,4 +62,4 @@ salarybracket_ga = gr.Interface(fn=salarybracket,
|
|
| 52 |
theme='dark'
|
| 53 |
)
|
| 54 |
|
| 55 |
-
salarybracket_ga.launch(share=True, debug=True)
|
|
|
|
| 19 |
|
| 20 |
# Define the function for making predictions
|
| 21 |
def salarybracket(age, workclass, education, marital_status, occupation, relationship, race, gender, native_country):
|
| 22 |
+
# Get the value associated with the selected label
|
| 23 |
+
workclass_value = next((v for k, v in mapping['workclass'].items() if k == workclass), None)
|
| 24 |
+
education_value = next((v for k, v in mapping['education'].items() if k == education), None)
|
| 25 |
+
marital_status_value = next((v for k, v in mapping['marital_status'].items() if k == marital_status), None)
|
| 26 |
+
occupation_value = next((v for k, v in mapping['occupation'].items() if k == occupation), None)
|
| 27 |
+
relationship_value = next((v for k, v in mapping['relationship'].items() if k == relationship), None)
|
| 28 |
+
race_value = next((v for k, v in mapping['race'].items() if k == race), None)
|
| 29 |
+
gender_value = next((v for k, v in mapping['gender'].items() if k == gender), None)
|
| 30 |
+
native_country_value = next((v for k, v in mapping['native_country'].items() if k == native_country), None)
|
| 31 |
+
|
| 32 |
+
inputs = np.array([[age, workclass_value, education_value, marital_status_value, occupation_value, relationship_value, race_value, gender_value, native_country_value]])
|
| 33 |
prediction = model.predict(inputs)
|
| 34 |
prediction_value = prediction[0][0] # Assuming the prediction is a scalar
|
| 35 |
result = "Income_bracket lesser than or equal to 50K ⬇️" if prediction_value <= 0.5 else "Income_bracket greater than 50K ⬆️"
|
|
|
|
| 40 |
for column, values in mapping.items():
|
| 41 |
options = []
|
| 42 |
for label, value in values.items():
|
| 43 |
+
options.append(label)
|
| 44 |
dropdown_options[column] = options
|
| 45 |
|
| 46 |
# Create the Gradio interface
|
|
|
|
| 62 |
theme='dark'
|
| 63 |
)
|
| 64 |
|
| 65 |
+
salarybracket_ga.launch(share=True, debug=True)
|