Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import joblib
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
# Load the scaler and models
|
6 |
+
scaler = joblib.load('scaler.joblib')
|
7 |
+
models = {target: joblib.load(f'svm_model_{target}.joblib') for target in ['processing', 'perception', 'input', 'understanding']}
|
8 |
+
|
9 |
+
app = Flask(__name__)
|
10 |
+
|
11 |
+
@app.route('/predict', methods=['POST'])
|
12 |
+
def predict():
|
13 |
+
data = request.json.get('user_input')
|
14 |
+
if not data:
|
15 |
+
return jsonify({"error": "No input provided"}), 400
|
16 |
+
|
17 |
+
user_input_array = np.array(data).reshape(1, -1)
|
18 |
+
user_input_scaled = scaler.transform(user_input_array)
|
19 |
+
|
20 |
+
predictions = {target: model.predict(user_input_scaled)[0] for target, model in models.items()}
|
21 |
+
|
22 |
+
return jsonify(predictions)
|
23 |
+
|
24 |
+
if __name__ == '__main__':
|
25 |
+
app.run(host='0.0.0.0', port=5000)
|