Commit 698a53a5 authored by Nirmal M.D.S's avatar Nirmal M.D.S

initial commit predict.py

parent 809ec1d5
from flask import Flask, request, jsonify
import pickle
import requests
from flask_cors import CORS
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
@app.route('/predict', methods=['POST'])
def predict():
try:
data = request.get_json()
task_description = data['task_description']
# Load the classifier and vectorizer from the .pickle files
with open('classifier.pickle', 'rb') as classifier_file:
classifier = pickle.load(classifier_file)
with open('vectorizer.pickle', 'rb') as vectorizer_file:
vectorizer = pickle.load(vectorizer_file)
task_vec = vectorizer.transform([task_description])
# Predict using the loaded model
prediction = classifier.predict(task_vec)[0]
return jsonify({'prediction': prediction})
except Exception as e:
return jsonify({'error': str(e)})
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000, debug=False)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment