Files
LLM_Engineering_OLD/week1/community-contributions/Movie_Suggestion.ipynb
2025-07-22 00:50:00 +05:30

105 lines
3.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "7bb9010e-48a8-491e-a2a9-1a8dacc26f87",
"metadata": {},
"source": [
"# Movie Suggestion using Ollama Running Locally\n",
"\n",
"#### Takes the user input like languages and Genre and suggests Top 10 Movies of the selected attributes.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad049302-dce8-4a0a-88ab-e485ac15fbe4",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from IPython.display import display, Markdown\n",
"\n",
"def get_movie_recommendations(language, genre, top_n=10, model='llama3.2'):\n",
" api_url = \"http://localhost:11434/api/generate\"\n",
" prompt = (\n",
" f\"Recommend {top_n} well-rated {language} movies from the {genre} genre. \"\n",
" \"For each movie, provide the name and a 1-2 sentence preview of its story. \"\n",
" \"Return the results as a Markdown table with columns: Title, Short Summary.\"\n",
" )\n",
" data = {\n",
" \"model\": model,\n",
" \"prompt\": prompt,\n",
" \"options\": {\"num_predict\": 800},\n",
" \"stream\": False\n",
" }\n",
" response = requests.post(api_url, json=data)\n",
" # Extract text response (could be markdown table already)\n",
" return response.json().get(\"response\", \"\").strip()"
]
},
{
"cell_type": "markdown",
"id": "01400553-419c-4798-8f19-e32e49379761",
"metadata": {},
"source": [
"#### Enter your Language and Genre"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a7527230-1e10-4b67-94c0-a84519b256c2",
"metadata": {},
"outputs": [],
"source": [
"language = input(\"Enter preferred language (e.g., French, Japanese): \").strip()\n",
"genre = input(\"Enter preferred genre (e.g., Drama, Comedy, Thriller): \").strip()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ff0146f-b37e-4218-9678-15a40bed3659",
"metadata": {},
"outputs": [],
"source": [
"recommendations_md = get_movie_recommendations(language, genre)\n",
"# This prints out the Markdown table as formatted by the Llama 3.2 model\n",
"from IPython.display import display, Markdown\n",
"\n",
"display(Markdown(recommendations_md))"
]
},
{
"cell_type": "markdown",
"id": "58cc0fa4-a2a6-4597-8ae9-39970fb2a7b5",
"metadata": {},
"source": [
"### The Result will be displayed in a markdown fashion in a neat table with rows and columns."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}