Hugo014 commited on
Commit
49c917a
·
verified ·
1 Parent(s): 5b0c088

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -1,14 +1,18 @@
1
- # Import necessary libraries
2
  import numpy as np
3
- import joblib # For loading the serialized model
4
- import pandas as pd # For data manipulation
5
- from flask import Flask, request, jsonify # For creating the Flask API
6
 
7
  # Initialize the Flask application
8
  super_kart_api = Flask("Super Kart Price Predictor")
9
 
10
- # Load the trained machine learning model (updated to match Super Kart model file)
11
- model = joblib.load("backend_files/super_kart_model_v1_0.joblib")
 
 
 
 
 
12
 
13
  # Define a route for the home page (GET request)
14
  @super_kart_api.get('/')
@@ -31,7 +35,6 @@ def predict_sales():
31
  input_data = request.get_json()
32
 
33
  # Extract relevant features from the JSON data
34
- # Note: Exclude Product_Id and Store_Id if they are not used in prediction
35
  sample = {
36
  'Product_Weight': input_data['Product_Weight'],
37
  'Product_Sugar_Content': input_data['Product_Sugar_Content'],
@@ -63,7 +66,7 @@ def predict_sales():
63
  predicted_sales = model.predict(features_df)[0]
64
 
65
  # If your model predicts log(sales), uncomment and use this instead:
66
- # predicted_log_sales = model.predict(features_df)[0]
67
  # predicted_sales = np.exp(predicted_log_sales)
68
 
69
  # Convert to Python float and round to 2 decimals
 
 
1
  import numpy as np
2
+ import joblib
3
+ import pandas as pd
4
+ from flask import Flask, request, jsonify
5
 
6
  # Initialize the Flask application
7
  super_kart_api = Flask("Super Kart Price Predictor")
8
 
9
+ # Load the trained machine learning model
10
+ model_path = "super_kart_model_v1_0.joblib" # Path after upload (root)
11
+ try:
12
+ model = joblib.load(model_path)
13
+ print(f"Model loaded successfully from {model_path}")
14
+ except FileNotFoundError:
15
+ raise FileNotFoundError(f"Model file not found at {model_path}. Ensure it's uploaded to the repo root.")
16
 
17
  # Define a route for the home page (GET request)
18
  @super_kart_api.get('/')
 
35
  input_data = request.get_json()
36
 
37
  # Extract relevant features from the JSON data
 
38
  sample = {
39
  'Product_Weight': input_data['Product_Weight'],
40
  'Product_Sugar_Content': input_data['Product_Sugar_Content'],
 
66
  predicted_sales = model.predict(features_df)[0]
67
 
68
  # If your model predicts log(sales), uncomment and use this instead:
69
+ # predicted_log_sales = model.predict(features_df)
70
  # predicted_sales = np.exp(predicted_log_sales)
71
 
72
  # Convert to Python float and round to 2 decimals