-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (24 loc) · 1.13 KB
/
app.py
File metadata and controls
33 lines (24 loc) · 1.13 KB
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
from flask import Flask, request, jsonify
import tensorflow as tf
import numpy as np
# Load mô hình đã train
model = tf.keras.models.load_model('video_recommendation_model_ver2.h5')
app = Flask(__name__)
# Định nghĩa route cho API
@app.route('/recommend', methods=['POST'])
def recommend():
try:
# Nhận dữ liệu từ request
data = request.json
user_history = data['user_history'] # Lịch sử xem video của người dùng
# Tiền xử lý dữ liệu trước khi đưa vào mô hình
input_data = np.array(user_history).reshape(1, -1) # Reshape để phù hợp với input của mô hình
# Dự đoán video đề xuất
predictions = model.predict(input_data)
# Chuyển kết quả về danh sách video đề xuất
recommended_videos = predictions[0].argsort()[-10:][::-1] # Lấy top 10 video
return jsonify({'recommended_videos': recommended_videos.tolist()})
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(debug=False, host='0.0.0.0', port=5050)