File size: 725 Bytes
e5bb506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd

movies = pd.read_csv('100_niche_movies.csv')

def recommend(query):
    query = query.lower()
    if "sci-fi" in query: genre = "Sci-Fi"
    elif "horror" in query: genre = "Horror" 
    elif "comedy" in query: genre = "Comedy"
    else: return movies.sample(3)
    
    return movies[movies['genres'].str.contains(genre)].sample(3)

with gr.Blocks() as demo:
    gr.Markdown("# 🎬 Your Personal Movie Assistant")
    query = gr.Textbox(label="What kind of movies?")
    output = gr.JSON(label="Recommendations")
    query.submit(
        fn=lambda q: recommend(q).to_dict('records'),
        inputs=query,
        outputs=output
    )

if __name__ == "__main__":
    demo.launch()