-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
79 lines (59 loc) · 1.92 KB
/
app.py
File metadata and controls
79 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from flask import Flask, render_template, request
import models.model_clus as model
import string
import pandas as pd
from sentence_transformers import SentenceTransformer
from sklearn.cluster import KMeans
import os
app = Flask(__name__)
# index route
@app.route('/')
def index():
return render_template('buganalyzer.html')
# cluster route
@app.route('/cluster')
def cluster():
return render_template('cluster.html')
# FAQ route
@app.route('/FAQ')
def FAQ():
return render_template('FAQ.html')
# scope route
@app.route('/scope')
def scope():
return render_template('scope.html')
# master run API route
@app.route('/api/v1.0/run')
def run():
# TODO:
# run model
err_count_arr, result = model.train_clus_model()
# update global values
# return required value
result = result.drop(['Clean data'], axis=1)
return err_count_arr, result.to_json()
# get error count from cluster number route
@app.route('/api/v1.0/get-err-count/<cluster_no>')
def get_error_count(cluster_no):
# TODO: get count from global value and return actual data
# dummy count
error_count = int(cluster_no) + 10
return str(error_count)
# upload csv, train model, and then return results
@app.route("/cluster/run", methods=["POST"])
def upload():
if request.method == "POST":
first_key = next(iter(request.files))
file = request.files[first_key]
if file.filename != "":
filename = file.filename
filePath = os.path.join("uploads", filename)
file.save(filePath)
# run model for dynamic file
err_count_arr, result = model.train_clus_model(filePath)
result = result.drop(['Clean data'], axis=1)
return render_template('cluster.html', err_count_arr = err_count_arr, result = result.to_json())
return "<h1>No file selected!</h1>"
# driver function
if __name__ == '__main__':
app.run(debug=True)