Gagan0141 commited on
Commit
b0c2eee
·
verified ·
1 Parent(s): 1c15bba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -8
app.py CHANGED
@@ -1,15 +1,14 @@
1
  from flask import Flask, request, render_template
2
- import pandas as pd
3
  from sklearn.linear_model import LogisticRegression
4
 
5
  # Load dataset
6
-
7
- df= sns.loadset("iris")
8
  X = df.iloc[:, :4].values
9
  y = df.iloc[:, 4].values
10
 
11
  # Train model
12
- model = LogisticRegression(max_iter=200)
13
  model.fit(X, y)
14
 
15
  # Flask app
@@ -24,13 +23,52 @@ def home():
24
  petal_length = float(request.form["petal_length"])
25
  petal_width = float(request.form["petal_width"])
26
 
27
- prediction = model.predict([[sepal_length, sepal_width, petal_length, petal_width]])[0]
28
- return render_template("index.html", prediction_text=f"Predicted Flower: {prediction}")
 
29
 
 
30
  except Exception as e:
31
- return render_template("index.html", prediction_text=f"Error: {e}")
32
 
33
  return render_template("index.html", prediction_text="")
34
 
35
  if __name__ == "__main__":
36
- app.run(host="0.0.0.0", port=7860, debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from flask import Flask, request, render_template
2
+ import seaborn as sns
3
  from sklearn.linear_model import LogisticRegression
4
 
5
  # Load dataset
6
+ df = sns.load_dataset("iris")
 
7
  X = df.iloc[:, :4].values
8
  y = df.iloc[:, 4].values
9
 
10
  # Train model
11
+ model = LogisticRegression(max_iter=200, multi_class="auto")
12
  model.fit(X, y)
13
 
14
  # Flask app
 
23
  petal_length = float(request.form["petal_length"])
24
  petal_width = float(request.form["petal_width"])
25
 
26
+ prediction = model.predict(
27
+ [[sepal_length, sepal_width, petal_length, petal_width]]
28
+ )[0]
29
 
30
+ return render_template("index.html", prediction_text=f"🌸 Predicted Flower: {prediction}")
31
  except Exception as e:
32
+ return render_template("index.html", prediction_text=f"⚠️ Error: {e}")
33
 
34
  return render_template("index.html", prediction_text="")
35
 
36
  if __name__ == "__main__":
37
+ app.run(host="0.0.0.0", port=7860, debug=True)
38
+
39
+ # from flask import Flask, request, render_template
40
+ # import pandas as pd
41
+ # from sklearn.linear_model import LogisticRegression
42
+
43
+ # # Load dataset
44
+
45
+ # df= sns.loadset("iris")
46
+ # X = df.iloc[:, :4].values
47
+ # y = df.iloc[:, 4].values
48
+
49
+ # # Train model
50
+ # model = LogisticRegression(max_iter=200)
51
+ # model.fit(X, y)
52
+
53
+ # # Flask app
54
+ # app = Flask(__name__)
55
+
56
+ # @app.route("/", methods=["GET", "POST"])
57
+ # def home():
58
+ # if request.method == "POST":
59
+ # try:
60
+ # sepal_length = float(request.form["sepal_length"])
61
+ # sepal_width = float(request.form["sepal_width"])
62
+ # petal_length = float(request.form["petal_length"])
63
+ # petal_width = float(request.form["petal_width"])
64
+
65
+ # prediction = model.predict([[sepal_length, sepal_width, petal_length, petal_width]])[0]
66
+ # return render_template("index.html", prediction_text=f"Predicted Flower: {prediction}")
67
+
68
+ # except Exception as e:
69
+ # return render_template("index.html", prediction_text=f"Error: {e}")
70
+
71
+ # return render_template("index.html", prediction_text="")
72
+
73
+ # if __name__ == "__main__":
74
+ # app.run(host="0.0.0.0", port=7860, debug=True)