-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
151 lines (110 loc) · 3.47 KB
/
app.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from fastapi import FastAPI
from fastapi.responses import FileResponse, PlainTextResponse
from fastapi.middleware.cors import CORSMiddleware
import pandas as pd
from functions.models import *
from functions.functions import *
app = FastAPI(
title="Recommendation Engine API",
description="""An API that utilises machine learning algorithms to recommends movies, anime, music, books, comics, manga and games.""",
version="0.0.1",
debug=True
)
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
favicon_path = "./images/favicon.png"
@app.get("/favicon.png", include_in_schema=False)
async def favicon():
return FileResponse(favicon_path)
# Home Page
@app.get("/", response_class=PlainTextResponse, tags=["home"])
async def home():
note = """
Recommendation Engine API 🙌🏻
This API recommends content such as games, movies, music, books and even anime!
Note: add "/redoc" to get the complete documentation.
"""
return note
# Movie API Route
@app.post(
"/movie",
summary="This endpoint recommends movies based on the movie genre and name.",
tags=["movies"]
)
async def movie(data: MovieAPI):
"""
This endpoint takes only one input, name of the movie.
"""
results = recommend_movie(data.movie)
return {"data": results}
# Anime Route
@app.post(
"/anime",
summary="This endpoint recommends anime based on the anime genre and name.",
tags=["anime"]
)
async def anime(data: AnimeAPI):
"""
This endpoint takes only one input, name of the anime.
"""
results = recommend_anime(data.anime)
return {"data": results}
# Spotify Music API Route
@app.post("/songs", summary="This endpoint recommends songs from user input", tags=["songs"])
async def songs(data: SongsAPI):
"""
This endpoint takes the following input
name: Name of the Song
year:Year the song was released
example input to test this route of the API:
{
"songs": [
{"name": "Come As You Are", "year":1991}
]
}
"""
df = pd.read_parquet("./data/music.parquet", engine="fastparquet")
results = recommend_songs(data.songs, df)
return {"data": results}
# Books Endpoint
@app.post("/books", summary="This endpoint recommends books from user input", tags=["books"])
async def music(data: BookAPI):
"""
This endpoint takes the following input
name: Name of the book
"""
results = recommend_book(data.book)
return {"data": results}
# Games API Route
@app.post("/games", summary="This endpoint recommends games from user input", tags=["games"])
async def games(data: GamesAPI):
"""
This endpoint takes the following input
name: Name of the game
"""
results = recommend_game(data.game)
return {"data": results}
# Manga API Route
@app.post("/manga", summary="This endpoint recommends manga from user input", tags=["manga"])
async def manga(data: MangaAPI):
"""
This endpoint takes the following input
name: Name of the manga
"""
results = recommend_manga(data.manga)
return {"data": results}
# Comics API Route
@app.post("/comics", summary="This endpoint recommends marvel comics from user input", tags=["comics"])
async def comics(data: ComicsAPI):
"""
This endpoint takes the following input
name: Name of the manga
"""
results = recommend_comics(data.comic)
return {"data": results}