| 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__) | |
| 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) |