-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
32 lines (25 loc) · 918 Bytes
/
api.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
32
from flask import Flask, request, jsonify
import main
from flask_cors import CORS
import requests
app = Flask(__name__)
CORS(app)
@app.route('/')
def hello_world():
return "Hello, World!"
@app.route('/recommend', methods=['POST'])
def recommend():
try:
data = request.get_json()
movie_title = data['movie_title']
similar_movies = main.find_similar(movie_title)
# Fetch movie details from the MovieDB API in the backend
movie_details = []
for movie_id in similar_movies:
response = requests.get(f"https://api.themoviedb.org/3/movie/{movie_id}?api_key=cef4366e188e22031754054cd680ec34&language=en-US")
movie_details.append(response.json())
return jsonify({'recommendations': movie_details})
except Exception as e:
return jsonify({'error': str(e)})
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000)