corrected templates
Lee Roy Stevenson committed
May 20, 2025 at 10:25 UTC
313628031c5533054f1d020e68e35cd544f4cc70
5 files changed
+50
-13
ai_request.py
+32
@@ -44,3 +44,35 @@ class AIRequest:
44
movie_recommendation = json_string.replace("```", "")
45
movie_recommendation = json.loads(movie_recommendation)
46
return movie_recommendation
47
+
48
+
49
+ def ai_excluded_movie_request(self,data_string: str, excluded_movie: str) -> dict:
50
+ """
51
+ Function to get an AI request for a movie recommendation excluding a ceratain movie
52
+ :param data_string:
53
+ :param excluded_movie:
54
+ :return: movie_recommendation
55
+ """
56
+ response = self.genai_client.models.generate_content(
57
+ model="gemini-2.0-flash",
58
+ contents="""Can you recommend a movie for me based on my ratings of the given dataset,
59
+ with personal ratings form 0 to 10 as float values, please?:
60
+ "dataset":"""+data_string+""" and excluding the movie: """+excluded_movie+"""
61
+ Please answer in the python dictionary format , so I can load the request into python.
62
+ Here an example:
63
+ {"movie":
64
+ {"title": "some title",
65
+ "director": "some director",
66
+ "year": "some year",
67
+ "poster": "movies's poster" as a string to load as link in html img tag,
68
+ "imdb": "some imdb id with only numbers please",
69
+ "country": "the country of the movie,
70
+ "genre": "the genre of the movie",
71
+ "plot": "the plot of the movie",},
72
+ "reasoning": "your reasoning text"}
73
+ Please only answer with the above format and nothing else.
74
+ """
75
+ )
76
+ json_string = response.text.replace("```python", "").replace("```", "")
77
+ movie_recommendation = json.loads(json_string)
78
+ return movie_recommendation
app.py
+5
-1
@@ -198,7 +198,11 @@ def recommendation(user_id):
198
data_string = ""
199
for movie in data_manager.get_user_movies(user_id):
200
data_string += f"Title: {movie["name"]} User Rating: {movie['user_rating']},"
201
- recommend = AIRequest().ai_request(data_string)
201
+ if "name" in request.form:
202
+ recommend = AIRequest().ai_excluded_movie_request(data_string,request.form[
203
+ "name"])
204
+ else:
205
+ recommend = AIRequest().ai_request(data_string)
206
poster = OMDBClient().get_movie(recommend["movie"]["title"])
207
recommend["movie"]["poster"] = poster["poster"]
208
recommend["movie"]["imdb"] = poster["rating"]
data_models.py
+1
-4
@@ -1,7 +1,4 @@
1
-from email.policy import default
2
-
3
-from flask_sqlalchemy.session import Session
4
-from sqlalchemy import create_engine, Column, Integer, String, Float, ForeignKey, Table
1
+from sqlalchemy import create_engine, Column, Integer, String, Float, ForeignKey
2
from sqlalchemy.orm import relationship, sessionmaker, declarative_base
3
4
# Define the database connection string. Use an in-memory database for testing.
requirements.txt
+11
-7
@@ -1,7 +1,11 @@
1
-Flask~=3.1.0
2
-pytest~=8.3.5
3
-SQLAlchemy~=2.0.40
4
-dotenv~=0.9.9
5
-python-dotenv~=1.1.0
6
-requests~=2.32.3
7
-google~=3.0.0
\ No newline at end of file
1
+Flask==3.1.0
2
+Flask-SQLAlchemy==3.1.1
3
+Flask-Login==0.6.3
4
+Flask-WTF==1.2.1
5
+SQLAlchemy==2.0.40
6
+Werkzeug==3.1.3
7
+pytest==8.3.5
8
+python-dotenv==1.1.0
9
+requests==2.32.3
10
+omdb==0.3.0
11
+sqlalchemy-utils==0.41.0
\ No newline at end of file
templates/recommend.html
+1
-1
@@ -18,7 +18,7 @@
18
Add to {{user.name}} Movies List</button>
19
</form>
20
<form action="/users/{{user.id}}/recommend_movie" method="POST">
21
- <button type="submit">Recommend different Movie</button>
21
+ <button type="submit" id = "name" name = "name" value="{{ movie.title }}">Recommend different Movie</button>
22
</form>
23
24
{% endblock %}