Spaces:
Runtime error
Runtime error
Adding information messages about the log path and prediction result
Browse files
app.py
CHANGED
|
@@ -38,12 +38,10 @@ print(f"saved_model_file_path: {saved_model_file_path}\n")
|
|
| 38 |
# Retrieve serialized model object
|
| 39 |
insurance_charge_predictor = joblib.load(filename=saved_model_file_path)
|
| 40 |
|
| 41 |
-
|
| 42 |
# Prepare the logging functionality
|
| 43 |
log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
|
| 44 |
log_folder = log_file.parent
|
| 45 |
-
print(f"\
|
| 46 |
-
|
| 47 |
|
| 48 |
# Scheduler will log every 2 API calls:
|
| 49 |
scheduler = CommitScheduler(
|
|
@@ -54,8 +52,10 @@ scheduler = CommitScheduler(
|
|
| 54 |
every=2
|
| 55 |
)
|
| 56 |
|
| 57 |
-
# Define the predict function which will take features, convert to dataframe and make predictions using the saved model
|
| 58 |
# the functions runs when 'Submit' is clicked or when a API request is made
|
|
|
|
|
|
|
| 59 |
#-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 60 |
def predict_insurance_charge(age, bmi, children, sex, smoker, region):
|
| 61 |
sample = {
|
|
@@ -89,12 +89,12 @@ def predict_insurance_charge(age, bmi, children, sex, smoker, region):
|
|
| 89 |
f.write("\n")
|
| 90 |
|
| 91 |
prediction_result = prediction[0][0]
|
| 92 |
-
print(f"\
|
| 93 |
-
#print(f"\nDebug -
|
| 94 |
-
#print(f"\nDebug -
|
| 95 |
return prediction_result
|
| 96 |
-
|
| 97 |
#return prediction[0]
|
|
|
|
| 98 |
#--------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 99 |
|
| 100 |
# Set up UI components for input and output
|
|
@@ -108,7 +108,6 @@ region_input = gr.Dropdown(['southeast', 'southwest', 'northeast', 'northwest'],
|
|
| 108 |
# Output component
|
| 109 |
model_output = gr.Label(label="Insurance Charge [$]")
|
| 110 |
|
| 111 |
-
|
| 112 |
# Create the gradio interface, make title "HealthyLife Insurance Charge Prediction"
|
| 113 |
demo = gr.Interface(
|
| 114 |
fn=predict_insurance_charge,
|
|
|
|
| 38 |
# Retrieve serialized model object
|
| 39 |
insurance_charge_predictor = joblib.load(filename=saved_model_file_path)
|
| 40 |
|
|
|
|
| 41 |
# Prepare the logging functionality
|
| 42 |
log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
|
| 43 |
log_folder = log_file.parent
|
| 44 |
+
print(f"\nInformation:\n\tlog_file: {log_file}\n\tlog_folder: {log_folder}\n")
|
|
|
|
| 45 |
|
| 46 |
# Scheduler will log every 2 API calls:
|
| 47 |
scheduler = CommitScheduler(
|
|
|
|
| 52 |
every=2
|
| 53 |
)
|
| 54 |
|
| 55 |
+
# Define the "predict function" which will take features, convert to dataframe and make predictions using the saved model
|
| 56 |
# the functions runs when 'Submit' is clicked or when a API request is made
|
| 57 |
+
# IMPORTANT Note: do not modify the names of keys for "sample" and "scheduler"; the keys should be named exactly as the names in the columns in the DataFrame.
|
| 58 |
+
# Otherwise, an run-time error will occur.
|
| 59 |
#-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 60 |
def predict_insurance_charge(age, bmi, children, sex, smoker, region):
|
| 61 |
sample = {
|
|
|
|
| 89 |
f.write("\n")
|
| 90 |
|
| 91 |
prediction_result = prediction[0][0]
|
| 92 |
+
print(f"\nPrediction result: {prediction_result} - {type(prediction_result)}\n")
|
| 93 |
+
#print(f"\nDebug - prediction[0]: {prediction[0]} - {type(prediction[0])}\n")
|
| 94 |
+
#print(f"\nDebug - prediction[0][0]: {prediction[0][0]} - {type(prediction[0][0])}\n")
|
| 95 |
return prediction_result
|
|
|
|
| 96 |
#return prediction[0]
|
| 97 |
+
#return prediction[0][0]
|
| 98 |
#--------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 99 |
|
| 100 |
# Set up UI components for input and output
|
|
|
|
| 108 |
# Output component
|
| 109 |
model_output = gr.Label(label="Insurance Charge [$]")
|
| 110 |
|
|
|
|
| 111 |
# Create the gradio interface, make title "HealthyLife Insurance Charge Prediction"
|
| 112 |
demo = gr.Interface(
|
| 113 |
fn=predict_insurance_charge,
|