Commit c3c6dffe authored by Udara Rangika's avatar Udara Rangika

api creation

parent 8b4ad902
from flask import Flask, request, jsonify
import pickle
import pandas as pd
from flask_cors import CORS # Import CORS
app = Flask(__name__)
CORS(app)
# Load the proficiency model
model_proficiency_path = 'weights/proficiency-rf.pickle'
with open(model_proficiency_path, 'rb') as f:
model_proficiency = pickle.load(f)
class_dict_rev = {
0: 'Basic',
1: 'Intermediate',
2: 'Advanced'
}
@app.route('/predict_proficiency', methods=['POST'])
def predict_proficiency():
try:
data = request.get_json()
sample_json = pd.DataFrame(data, index=[0]).values
pred = model_proficiency.predict(sample_json)[0]
predicted_class = class_dict_rev[pred]
result = {'predicted_class': predicted_class}
return jsonify(result)
except Exception as e:
return jsonify({'error': str(e)})
if __name__ == '__main__':
app.run(debug=True)
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