Skip to content

Commit eeb8904

Browse files
committed
update api
1 parent 30811d7 commit eeb8904

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def index():
3232
return render_template('form.html')
3333

3434
@app.route('/predict', methods=['POST','GET'])
35-
def process():
35+
def predict():
3636
if request.method == 'POST':
3737
name = request.form['name']
3838
data = [name]
@@ -44,15 +44,15 @@ def process():
4444
return jsonify({'error':result})
4545
return jsonify({'name':result})
4646
elif request.method=='GET':
47-
name = request.args.get('nameInput')
47+
name = request.args.get('commentInput')
4848
data = [name]
4949
vect = cv.transform(data).toarray()
5050
my_prediction = clf.predict(vect)
5151
result = "Not a Spam"
5252
if my_prediction == 'spam':
5353
result="Spam"
54-
return jsonify({'error':result})
55-
return jsonify({'name':result})
54+
return jsonify({'outcome':result})
55+
return jsonify({'outcome':result})
5656

5757

5858
# email = request.form['email']

static/js/form.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
12
$(document).ready(function() {
23

34
$('form').on('input', function(event) {
4-
5+
// console.log($('#commentInput').val());
56
$.ajax({
67
data : {
7-
name : $('#nameInput').val(),
8-
// email : $('#emailInput').val()
8+
comment : $('commentInput').val(),
9+
10+
911
},
1012
type : 'POST',
1113
url : '/predict'
14+
1215
})
1316
.done(function(data) {
17+
console.log(data);
1418

1519
if (data.error) {
1620
$('#errorAlert').text(data.error).show();
@@ -22,6 +26,7 @@ $(document).ready(function() {
2226
}
2327

2428
});
29+
2530

2631
event.preventDefault();
2732

templates/form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
Spam Comment Detector
5757
<form class="form-inline">
5858
<div class="form-group">
59-
<input type="text" class="form-control" id="nameInput" placeholder="Type Here" style="height:40px;font-size:20pt;" size="40%">
59+
<input type="text" class="form-control" id="nameInput" name="commentInput" placeholder="Type Here" style="height:40px;font-size:20pt;" size="40%">
6060
</div>
6161
</form>
6262
<div id="successAlert" class="alert alert-success" role="alert" style="display:none; width:50%;"></div>

0 commit comments

Comments
 (0)