use ajax to fix sentiment result display on text input
Browse files
main.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import os
|
2 |
-
from flask import Flask, request, render_template
|
3 |
import pandas as pd
|
4 |
import torch
|
5 |
from transformers import BertTokenizer, BertForSequenceClassification
|
@@ -65,10 +65,10 @@ def analyze_text():
|
|
65 |
text = request.form.get('text', '').strip()
|
66 |
|
67 |
if not text:
|
68 |
-
return
|
69 |
|
70 |
sentiment = predict_sentiment(text)
|
71 |
-
return
|
72 |
|
73 |
@app.route('/uploader', methods=['POST'])
|
74 |
def upload_file_post():
|
|
|
1 |
import os
|
2 |
+
from flask import Flask, jsonify, request, render_template
|
3 |
import pandas as pd
|
4 |
import torch
|
5 |
from transformers import BertTokenizer, BertForSequenceClassification
|
|
|
65 |
text = request.form.get('text', '').strip()
|
66 |
|
67 |
if not text:
|
68 |
+
return jsonify({"error": "No text provided!"}), 400 # Return JSON error message
|
69 |
|
70 |
sentiment = predict_sentiment(text)
|
71 |
+
return jsonify({"sentiment": sentiment}) # Return JSON response
|
72 |
|
73 |
@app.route('/uploader', methods=['POST'])
|
74 |
def upload_file_post():
|