Add files via upload

This commit is contained in:
Cris Charles authored and GitHub committed 2026-03-01 22:15:02 +08:00
commit 657b2877fe
2 files changed
+43

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
from flask import Flask, request, jsonify
from sklearn.linear_model import LinearRegression
import numpy as np
app = Flask(__name__)
# 1. Create a simple dataset (X = Input, y = Output)
# We are teaching the model that y is roughly 2 times X
X = np.array([[1], [2], [3], [4], [5]])
y = np.array([2, 4, 6, 8, 10])
# 2. Train the model
model = LinearRegression()
model.fit(X, y)
@app.route('/')
def home():
return "ML API is running! Use the /predict endpoint."
@app.route('/predict', methods=['GET'])
def predict():
try:
# Get the 'value' parameter from the URL (e.g., /predict?value=10)
user_input = request.args.get('value')
if user_input is None:
return jsonify({"error": "Please provide a 'value' parameter"}), 400
prediction = model.predict([[float(user_input)]])
return jsonify({
"input": user_input,
"prediction": prediction[0]
})
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
+4
View File
@@ -0,0 +1,4 @@
flask
scikit-learn
numpy
gunicorn