-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.py
31 lines (23 loc) · 863 Bytes
/
Server.py
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
from flask import Flask, request, jsonify
import subprocess
import json
app = Flask(__name__)
@app.route('/get_recommendations', methods=['POST'])
def get_recommendations():
# Extract song and artist from the request
data = request.json
song = data.get('song')
artist = data.get('artist')
if not song or not artist:
return jsonify({"error": "Song and artist are required."}), 400
try:
result = subprocess.run(['./main.exe', song, artist], capture_output=True, text=True)
if result.returncode != 0:
raise Exception(result.stderr)
# Parse the C++ program's output as JSON
recommendations = json.loads(result.stdout)
return jsonify(recommendations)
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(debug=True)