Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask
|
| 2 |
+
import seaborn as sns
|
| 3 |
+
from sklearn.linear_model import LogisticRegression
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
# Train model once at startup (faster than retraining every request)
|
| 8 |
+
iris1 = sns.load_dataset("iris")
|
| 9 |
+
modlog = LogisticRegression(max_iter=300)
|
| 10 |
+
|
| 11 |
+
irisarr = iris1.values
|
| 12 |
+
X = irisarr[:, 0:4]
|
| 13 |
+
Y = irisarr[:, 4]
|
| 14 |
+
modlog.fit(X, Y)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@app.route('/')
|
| 18 |
+
def hello_world():
|
| 19 |
+
# Test sample (setosa)
|
| 20 |
+
sl, sw, pl, pw = 5.1, 3.5, 1.4, 0.2
|
| 21 |
+
res = modlog.predict([[sl, sw, pl, pw]])
|
| 22 |
+
return "Hello, AIML July 25 batch — Predicted: " + str(res[0])
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
# Debug mode for development
|
| 27 |
+
app.run(debug=True, host="0.0.0.0", port=5000)
|