Spaces:
Sleeping
Sleeping
| from flask import Flask, request, render_template | |
| import pandas as pd | |
| from sklearn.linear_model import LogisticRegression | |
| # Load dataset | |
| url = "https://raw.githubusercontent.com/sarwansingh/Python/master/ClassExamples/data/iris.csv" | |
| df = pd.read_csv(url, header=None) | |
| 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__) | |
| 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) |