Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
|
|
|
| 3 |
|
| 4 |
# Load the pickled model
|
| 5 |
model = tf.keras.models.load_model("census.h5")
|
| 6 |
|
| 7 |
# Define the function for making predictions
|
| 8 |
def salarybracket(age, workclass, education, education_num, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country):
|
| 9 |
-
inputs = [[age, workclass, education, education_num, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country]]
|
| 10 |
prediction = model.predict(inputs)
|
| 11 |
-
prediction_value = prediction[0]
|
| 12 |
-
|
| 13 |
-
# Categorize prediction_value
|
| 14 |
-
if prediction_value == 0:
|
| 15 |
-
result = "Income_bracket lesserthan or equal to 50K "
|
| 16 |
-
else:
|
| 17 |
-
result = "Income_bracket greater than to 50K"
|
| 18 |
-
|
| 19 |
return f"Income_bracket Prediction: {prediction_value} \n\nResult: {result}"
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
# Create the Gradio interface
|
| 24 |
salarybracket_ga = gr.Interface(fn=salarybracket,
|
| 25 |
inputs = [
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
|
| 5 |
# Load the pickled model
|
| 6 |
model = tf.keras.models.load_model("census.h5")
|
| 7 |
|
| 8 |
# Define the function for making predictions
|
| 9 |
def salarybracket(age, workclass, education, education_num, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country):
|
| 10 |
+
inputs = np.array([[age, workclass, education, education_num, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country]])
|
| 11 |
prediction = model.predict(inputs)
|
| 12 |
+
prediction_value = prediction[0][0] # Assuming the prediction is a scalar
|
| 13 |
+
result = "Income_bracket lesser than or equal to 50K" if prediction_value <= 0.5 else "Income_bracket greater than 50K"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
return f"Income_bracket Prediction: {prediction_value} \n\nResult: {result}"
|
| 15 |
|
| 16 |
+
|
|
|
|
| 17 |
# Create the Gradio interface
|
| 18 |
salarybracket_ga = gr.Interface(fn=salarybracket,
|
| 19 |
inputs = [
|