Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- Dockerfile +3 -13
- app.py +19 -31
Dockerfile
CHANGED
|
@@ -1,16 +1,6 @@
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
-
|
| 3 |
-
# Set the working directory inside the container
|
| 4 |
WORKDIR /app
|
| 5 |
-
|
| 6 |
-
# Copy all files from the current directory to the container's working directory
|
| 7 |
COPY . .
|
| 8 |
-
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# Define the command to start the application using Gunicorn with 4 worker processes
|
| 13 |
-
# - `-w 4`: Uses 4 worker processes for handling requests
|
| 14 |
-
# - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
|
| 15 |
-
# - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
|
| 16 |
-
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:superkart_api"]
|
|
|
|
| 1 |
FROM python:3.9-slim
|
|
|
|
|
|
|
| 2 |
WORKDIR /app
|
|
|
|
|
|
|
| 3 |
COPY . .
|
| 4 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 5 |
+
# Important: app:app refers to app.py and the Flask instance named 'app'
|
| 6 |
+
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,40 +1,28 @@
|
|
| 1 |
-
|
| 2 |
-
# Import necessary libraries
|
| 3 |
import numpy as np
|
| 4 |
-
import joblib
|
| 5 |
-
import pandas as pd
|
| 6 |
-
from flask import Flask, request, jsonify
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
|
| 11 |
-
# Load the
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
@superkart_api.get('/')
|
| 16 |
def home():
|
| 17 |
-
return
|
| 18 |
|
| 19 |
-
|
| 20 |
-
@superkart_api.post('/v1/predict')
|
| 21 |
def predict_sales():
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
input_data = pd.DataFrame([data])
|
| 30 |
-
|
| 31 |
-
# Make a churn prediction using the trained model
|
| 32 |
-
prediction = model.predict(input_data).tolist()[0]
|
| 33 |
-
|
| 34 |
-
# Return the prediction as a JSON response
|
| 35 |
-
return jsonify({'Sales': prediction})
|
| 36 |
-
|
| 37 |
|
| 38 |
-
# Run the Flask app in debug mode
|
| 39 |
if __name__ == '__main__':
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from flask import Flask, request, jsonify
|
| 5 |
|
| 6 |
+
# Create the Flask app - the name 'app' is standard for Gunicorn
|
| 7 |
+
app = Flask(__name__)
|
| 8 |
|
| 9 |
+
# Load the model from the local directory inside the container
|
| 10 |
+
# Note: backend_files contains Extraalearn.joblib, so in the container it's just 'Extraalearn.joblib'
|
| 11 |
+
model = joblib.load('Extraalearn.joblib')
|
| 12 |
|
| 13 |
+
@app.get('/')
|
|
|
|
| 14 |
def home():
|
| 15 |
+
return 'ExtraaLearn API is Running'
|
| 16 |
|
| 17 |
+
@app.post('/v1/predict')
|
|
|
|
| 18 |
def predict_sales():
|
| 19 |
+
try:
|
| 20 |
+
data = request.get_json()
|
| 21 |
+
input_data = pd.DataFrame([data])
|
| 22 |
+
prediction = model.predict(input_data).tolist()[0]
|
| 23 |
+
return jsonify({'Sales': float(prediction)})
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return jsonify({'error': str(e)}), 400
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
|
|
|
| 27 |
if __name__ == '__main__':
|
| 28 |
+
app.run(host='0.0.0.0', port=7860)
|