Spaces:
Sleeping
Sleeping
Commit
·
1102829
1
Parent(s):
45d42ac
Create main.py
Browse files
main.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify, render_template
|
2 |
+
from flask_cors import CORS
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
from sklearn.linear_model import LogisticRegression
|
6 |
+
|
7 |
+
app = Flask(__name__)
|
8 |
+
app.static_folder = 'static'
|
9 |
+
app.static_url_path = '/static'
|
10 |
+
|
11 |
+
app.secret_key = "flask-nielit-2023"
|
12 |
+
|
13 |
+
CORS(app)
|
14 |
+
|
15 |
+
@app.route('/')
|
16 |
+
def iris():
|
17 |
+
return render_template("index.html")
|
18 |
+
|
19 |
+
@app.route('/irisf', methods=["POST"])
|
20 |
+
def page():
|
21 |
+
swidth=eval(request.form.get("swidth"))
|
22 |
+
sheight=eval(request.form.get("sheight"))
|
23 |
+
pwidth=eval(request.form.get("pwidth"))
|
24 |
+
pheight=eval(request.form.get("pheight"))
|
25 |
+
|
26 |
+
url="https://raw.githubusercontent.com/lovnishverma/datasets/main/iris.csv"
|
27 |
+
|
28 |
+
data=pd.read_csv(url, header=None)
|
29 |
+
flower=data.values
|
30 |
+
|
31 |
+
#Split
|
32 |
+
x=flower[:,:4]
|
33 |
+
y=flower[:,-1]
|
34 |
+
|
35 |
+
model=LogisticRegression()
|
36 |
+
model.fit(x,y)
|
37 |
+
|
38 |
+
arr=model.predict([[swidth,sheight,pwidth,pheight]])
|
39 |
+
|
40 |
+
return render_template("index.html", data=str(arr[0]))
|
41 |
+
|
42 |
+
|
43 |
+
if __name__ == '__main__':
|
44 |
+
app.run()
|