Commit 8bfaa91c authored by Udara Rangika Herath's avatar Udara Rangika Herath

Merge branch 'it20617400/proficiency_level_detection' into 'master'

api creation

See merge request 2023-24-027/implementation-of-an-intelligent-virtual-tutor-to-enhance-english-vocabulary-skills-of-grade-6-students!5
parents feeb76c8 c3c6dffe
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