Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # Define a dictionary with movie genres, recommendations, and image URLs (movies from 2020 and after) | |
| movie_recommendations = { | |
| "action": [ | |
| {"title": "Spider-Man: No Way Home", "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTtauzk4w5HwCXrx3nAm5VTFcywz62gV18C3A7KFT03SgB2k8c0"}, | |
| {"title": "No Time to Die", "image": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRx46SP8e0e7gE03uy9wlxfYYTwEufzGFpOcQ24W735sam1iTUy"}, | |
| {"title": "F9: The Fast Saga", "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSuBoWrjuaebk6iO7q32iL4d1fXXxHxGONn_ZFYpUW6ZEdkFoSx"}, | |
| ], | |
| "comedy": [ | |
| {"title": "Barbie", "image": "https://sm.ign.com/ign_mear/gallery/b/barbie-mov/barbie-movie-character-posters_ezhz.jpg"}, | |
| {"title": "Free Guy", "image": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSI48Ohi0Zng9Jzb89gzgWxWgO4aLHQk7dJd-P4Pi4aWMX0oW7JTsQj8wYibOKiW8_A1RkZ"}, | |
| {"title": "The Mitchells vs. the Machines", "image": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRbhSTVifZCh_JxYi_jDzOay15jas5p2NSXqarG8Es_66sL5VEDdaQK561j0GVL3oKT6eIteQ"}, | |
| ], | |
| "drama": [ | |
| {"title": "Nomadland", "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRgtE2DrWPRETen9WbvQj6bTfjNKsfYjIZu3xgLqVa1isn9SdaK3GW5VbnRq-Ikh3PjBg1U-Q"}, | |
| {"title": "It Ends with Us", "image": "https://m.media-amazon.com/images/M/MV5BYzM2NGMzNGQtZjNhMi00MTVkLTg2ZGQtN2M4OTllYzU1Y2Y0XkEyXkFqcGc@._V1_.jpg"}, | |
| ], | |
| "sci-fi": [ | |
| {"title": "Dune", "image": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTzGMepFMvymqy06LF-NsSpgYxeujNWwbXto-bc868K2bl8-zu6"}, | |
| {"title": "Tenet", "image": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTYoAGfY4ffCXIoBdPYfxypbrvpGxQ5FA6w0r3ihzqzMZ5kxMaPXWGE50muitVS2CULBCdGvg"}, | |
| {"title": "The Matrix Resurrections", "image": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSLhb7X31qkx7zGJ8mJCYkWyUOvmhGE8bOK2TMt-XPx8ZjnA0wTviszikkWd0NoKWkdOhqwpg"}, | |
| ], | |
| "horror": [ | |
| {"title": "A Quiet Place Part II", "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRYMLrYDo_n4HcM311PprAKXt_l87csDaMQWNzTuYqpkV_MvWnohVNKI911XdEdcpjR8lLpKw"}, | |
| {"title": "Alive", "image": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQkQT9cSSis5q40Ezj58v1k2Lfn_llWmCe7djfVDiyyTPxHIttt"}, | |
| {"title": "Escape Room", "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTOUj1ZQtDt6tZLasXxCl57iY7d4CXD5HGStsbrJydDsynQSvkW-wpajUGWQ4tLWzHq8JCTkA"}, | |
| ], | |
| "romance": [ | |
| {"title": "The Hating Game", "image": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcR8iZhh_rC1GoC9j-So30MJJAxrbTN7-sePwda-QFXA9rGItpXo1ZtDrXNvAJrePYbiveZP8A"}, | |
| {"title": "To All the Boys: Always and Forever", "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR8LLDi6E12XCRe7Syq5ukLSXIGbnwJtdRvaCG0eSs5svbq390QJjReUlSyAOzqV-wInhwt"}, | |
| ], | |
| "animation": [ | |
| {"title": "Inside Out 2", "image": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTVXIXVwclOPh5eUuVyKhE_osTsavNc-56-oR7z7xwmOOP6--wJaVl7jmVOG2lBqBb02_ndTQ"}, | |
| {"title": "The Boy and the Heron", "image": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSqmD_K_HfRHJAp69m3jwcJMKLCtiB5vFl045PyUOoTYxxRzHB8x-vJqOhMcDGiKIvEzqnf"}, | |
| {"title": "Luca", "image": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQhQZlzN2TDvMHk-ByF881UtRBHwP_yHZa5mamNFjscuc-GTpfYxUEoqIZMho6JPwlO-Wx2xg"}, | |
| ], | |
| "family": [ | |
| {"title": "Soul", "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTI5zYGoeyiMInSndukTQs4VnSfQX9uoMz2AVPjib6S5XfWdDUODk8mCb2JKPRNrF1k3HUBeg"}, | |
| {"title": "If", "image": "https://upload.wikimedia.org/wikipedia/en/a/a7/IF_%28film%29_poster_2.jpg"}, | |
| ] | |
| } | |
| # Add the rest of your code for the Gradio app below this line... | |
| # Function to recommend a movie based on the genre | |
| def recommend_movie(genre): | |
| genre = genre.lower() | |
| if genre in movie_recommendations: | |
| recommendations = [] | |
| for movie in movie_recommendations[genre]: | |
| recommendations.append(f"{movie['title']}\n![{movie['title']}]({movie['image']})") | |
| return f"Here are some {genre.capitalize()} movie recommendations:\n\n" + "\n\n".join(recommendations) | |
| else: | |
| return "Sorry, we don't have recommendations for that genre. Please try another genre." | |
| # Create a Gradio interface | |
| demo = gr.Interface(fn=recommend_movie, inputs="text", outputs="markdown", title="Movie Recommendation System", description="Enter a movie genre to get recommendations.") | |
| # Launch the Gradio app | |
| demo.launch() | |