-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
36 lines (26 loc) · 1 KB
/
application.py
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
from flask import Flask, request, jsonify
import pickle
import os
application = Flask(__name__)
def load_model():
with open("count_vectorizer.pkl", "rb") as vec_file:
vectorizer = pickle.load(vec_file)
with open("basic_classifier.pkl", "rb") as clf_file:
classifier = pickle.load(clf_file)
return vectorizer, classifier
vectorizer, classifier = load_model()
@application.route('/predict', methods=['POST'])
def predict():
data = request.json
text = data.get('text', '')
# Vectorize the text using the preloaded vectorizer
transformed_text = vectorizer.transform([text])
# Use the classifier to make a prediction
prediction = classifier.predict(transformed_text)[0]
# Map the string output to integer
label_map = {'FAKE': 1, 'REAL': 0}
int_prediction = label_map.get(prediction, -1)
# Return the result as JSON
return jsonify({'prediction': int_prediction})
if __name__ == "__main__":
application.run(host="127.0.0.1",port=5000, debug=True)