irisproject / app.py
LovnishVerma's picture
Update app.py
2371a68 verified
from flask import Flask, render_template, request
import pandas as pd
from sklearn.linear_model import LogisticRegression
app = Flask(__name__)
# Load dataset from URL
iris = pd.read_csv("iris.csv")
# Prepare input and output
X = iris[['sepal_length', 'sepal_width', 'petal_length', 'petal_width']]
y = iris['species']
# Logistic Regression
model = LogisticRegression()
model.fit(X, y) # Train once
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
sl = float(request.form['sepal_length'])
sw = float(request.form['sepal_width'])
pl = float(request.form['petal_length'])
pw = float(request.form['petal_width'])
# Predict species
input_data = [[sl, sw, pl, pw]]
pred = model.predict(input_data)
return render_template('index.html', prediction=pred[0])
if __name__ == '__main__':
app.run(debug=True)