File size: 2,369 Bytes
9668cbe
b0c2eee
9668cbe
db940bb
9668cbe
b0c2eee
9668cbe
 
0483f56
9668cbe
b0c2eee
9668cbe
db940bb
9668cbe
2ca1f10
db940bb
9668cbe
 
 
 
 
 
 
 
8653d9b
b0c2eee
 
 
8653d9b
b0c2eee
9668cbe
b0c2eee
8653d9b
9668cbe
8653d9b
2ca1f10
b0c2eee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from flask import Flask, request, render_template
import seaborn as sns
from sklearn.linear_model import LogisticRegression

# Load dataset
df = sns.load_dataset("iris")
X = df.iloc[:, :4].values
y = df.iloc[:, 4].values

# Train model
model = LogisticRegression(max_iter=200, multi_class="auto")
model.fit(X, y)

# Flask app
app = Flask(__name__)

@app.route("/", methods=["GET", "POST"])
def home():
    if request.method == "POST":
        try:
            sepal_length = float(request.form["sepal_length"])
            sepal_width = float(request.form["sepal_width"])
            petal_length = float(request.form["petal_length"])
            petal_width = float(request.form["petal_width"])

            prediction = model.predict(
                [[sepal_length, sepal_width, petal_length, petal_width]]
            )[0]

            return render_template("index.html", prediction_text=f"🌸 Predicted Flower: {prediction}")
        except Exception as e:
            return render_template("index.html", prediction_text=f"⚠️ Error: {e}")

    return render_template("index.html", prediction_text="")

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860, debug=True)

# from flask import Flask, request, render_template
# import pandas as pd
# from sklearn.linear_model import LogisticRegression

# # Load dataset

# df= sns.loadset("iris")
# X = df.iloc[:, :4].values
# y = df.iloc[:, 4].values

# # Train model
# model = LogisticRegression(max_iter=200)
# model.fit(X, y)

# # Flask app
# app = Flask(__name__)

# @app.route("/", methods=["GET", "POST"])
# def home():
#     if request.method == "POST":
#         try:
#             sepal_length = float(request.form["sepal_length"])
#             sepal_width = float(request.form["sepal_width"])
#             petal_length = float(request.form["petal_length"])
#             petal_width = float(request.form["petal_width"])

#             prediction = model.predict([[sepal_length, sepal_width, petal_length, petal_width]])[0]
#             return render_template("index.html", prediction_text=f"Predicted Flower: {prediction}")

#         except Exception as e:
#             return render_template("index.html", prediction_text=f"Error: {e}")

#     return render_template("index.html", prediction_text="")

# if __name__ == "__main__":
#     app.run(host="0.0.0.0", port=7860, debug=True)