File size: 2,016 Bytes
4cc5afe |
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 |
import gradio as gr
from transformers import pipeline
# Load the movie recommendation model
model_name = "AventIQ-AI/all-MiniLM-L6-v2-movie-recommendation-system"
retriever = pipeline("feature-extraction", model=model_name)
def recommend_movies(movie_description):
"""Generates movie recommendations based on user input."""
if not movie_description.strip():
return "β οΈ Please enter a movie description or genre."
# Dummy output (replace with actual model inference logic)
recommendations = [
"Inception (2010)",
"Interstellar (2014)",
"The Matrix (1999)",
"Blade Runner 2049 (2017)",
"The Dark Knight (2008)"
]
return "\n".join(recommendations[:3]) # Return top 3 recommendations
# Example Inputs
example_descriptions = [
"A mind-bending sci-fi thriller about dreams within dreams.",
"A group of superheroes saves the world from an alien invasion.",
"A gripping crime drama featuring a brilliant detective.",
"A heartwarming animated movie about friendship and adventure."
]
# Create Gradio UI
with gr.Blocks() as demo:
gr.Markdown("## π¬ AI-Powered Movie Recommendation System")
gr.Markdown("Enter a movie description or genre, and the model will suggest similar movies!")
with gr.Row():
input_text = gr.Textbox(label="π₯ Enter a movie description or genre:",
placeholder="Example: A sci-fi adventure through space and time.")
recommend_button = gr.Button("π Get Recommendations")
output_text = gr.Textbox(label="πΏ Recommended Movies:")
gr.Markdown("### π Example Inputs")
example_buttons = [gr.Button(example) for example in example_descriptions]
for btn in example_buttons:
btn.click(fn=lambda text=btn.value: text, outputs=input_text)
recommend_button.click(recommend_movies, inputs=input_text, outputs=output_text)
# Launch the Gradio app
demo.launch() |