Moiz commited on
Commit
6275709
Β·
1 Parent(s): d997e10

changed display, edited readme

Browse files
Files changed (6) hide show
  1. .DS_Store +0 -0
  2. README.md +11 -0
  3. app.py +79 -69
  4. assets/imdblogo.png +0 -0
  5. assets/metacritic.png +0 -0
  6. assets/rotten.png +0 -0
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
README.md CHANGED
@@ -12,3 +12,14 @@ short_description: Private Project
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
15
+
16
+
17
+
18
+
19
+ imdb_top250.html - is a html save of the top 250 movies list on imdb.com
20
+ imdb-scrape250.py - script to get list of movieID for all the 250 movies in the html (Saved in imdb_movie_codes.csv)
21
+
22
+ database.py - script to populate a dataframe with all the important API fetch (saved in MovieDatabase.csv)
23
+
24
+
25
+
app.py CHANGED
@@ -1,81 +1,91 @@
 
1
  import gradio as gr
2
- import requests
3
  import pandas as pd
4
 
5
- #load csv
6
- try:
7
- df = pd.read_csv('/Users/moizpro/Desktop/MoviesRecommender/MovieRecommender/imdb_movie_codes.csv')
8
- print("df loaded..")
9
- except FileNotFoundError:
10
- print(f"Error: CSV file not found at path")
11
- #access frist movieID
12
- try:
13
- # Initialize current movie index
14
- current_movie_index = 0
15
- # Assign the first element
16
- movie_id = df.iloc[current_movie_index, 0]
17
- # Print the value
18
- print(movie_id)
19
- except:
20
- print("error fetching first element")
21
 
22
- # Function to fetch movie details using the given movie ID
23
- def fetch_movie_info(movie_id):
24
- api_key = "f2443b04"
25
- url = f"http://www.omdbapi.com/?apikey={api_key}&i={movie_id}&plot=full"
26
- response = requests.get(url)
27
-
28
- if response.status_code == 200:
29
- movie_data = response.json()
30
- if movie_data.get("Response") == "True":
31
- title = movie_data.get("Title", "N/A")
32
- year = movie_data.get("Year", "N/A")
33
- plot = movie_data.get("Plot", "N/A")
34
- imdb_rating = movie_data.get("imdbRating", "N/A")
35
- box_office = movie_data.get("BoxOffice", "N/A")
36
- genre = movie_data.get("Genre", "N/A")
37
-
38
- return title, year, genre, plot, imdb_rating, box_office
39
- else:
40
- return "Error", "Error", "Error", "Error", "Error", "Error"
41
- else:
42
- return f"Failed to fetch movie details. HTTP Status Code: {response.status_code}"
43
 
44
- # Function to update movie details for the next movie
45
- def update_movie_details():
46
- global current_movie_index
47
- print(current_movie_index)
48
- movie_id = df.iloc[current_movie_index, 0]
49
- print(movie_id)
50
- current_movie_index = (current_movie_index + 1) % len(df) # Loop back to start
51
- return fetch_movie_info(movie_id)
52
 
53
- # Gradio interface
54
- with gr.Blocks(css="styles.css") as app:
55
- gr.Markdown("# Movie Information Display")
56
- gr.Markdown("This app fetches and displays movie information from a list of IMDb movie IDs.")
57
-
58
- # Initial movie details (fetch the first movie)
59
- initial_movie_details = update_movie_details()
60
-
61
- title_output = gr.Textbox(label="Title", lines=1, value=initial_movie_details[0])
62
- year_output = gr.Textbox(label="Year", lines=1, value=initial_movie_details[1])
63
- genre_output = gr.Textbox(label="Genre", lines=1, value=initial_movie_details[2])
64
- plot_output = gr.Textbox(label="Plot", lines=5, value=initial_movie_details[3])
65
- imdb_rating_output = gr.Textbox(label="IMDb Rating", lines=1, value=initial_movie_details[4])
66
- box_office_output = gr.Textbox(label="Box Office", lines=1, value=initial_movie_details[5])
67
-
68
- # Slider for user rating (optional)
69
- slider = gr.Slider(minimum=0, maximum=10, step=0.25, label="Rating Slider")
70
 
71
- # Button to fetch next movie
72
- next_button = gr.Button("Next")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- # Action on button click
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  next_button.click(
76
- fn=update_movie_details,
77
- inputs=[],
78
- outputs=[title_output, year_output, genre_output, plot_output, imdb_rating_output, box_office_output]
79
  )
80
 
 
81
  app.launch()
 
1
+ import base64
2
  import gradio as gr
 
3
  import pandas as pd
4
 
5
+ # Load the dataset
6
+ data = pd.read_csv('MovieDatabase.csv')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ # Initialize the current index
9
+ current_index = [0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ def encode_image(image_path):
12
+ with open(image_path, "rb") as img_file:
13
+ return f"data:image/png;base64,{base64.b64encode(img_file.read()).decode('utf-8')}"
 
 
 
 
 
14
 
15
+ # Encode images as base64
16
+ imdb_logo = encode_image("assets/imdblogo.png")
17
+ rotten_logo = encode_image("assets/rotten.png")
18
+ metacritic_logo = encode_image("assets/metacritic.png")
19
+
20
+ def display_movie(action):
21
+ # Update the index based on action
22
+ if action == "next" and current_index[0] < len(data) - 1:
23
+ current_index[0] += 1
24
+ elif action == "prev" and current_index[0] > 0:
25
+ current_index[0] -= 1
 
 
 
 
 
 
26
 
27
+ # Extract movie details
28
+ movie = data.iloc[current_index[0]]
29
+ details = {
30
+ "title": f"# {movie['Title']}",
31
+ "poster_placeholder": "πŸŽ₯ Movie Poster Placeholder πŸŽ₯",
32
+ "ratings": f"""
33
+ <div style="display: flex; gap: 15px; align-items: center;">
34
+ <div style="text-align: center;">
35
+ <img src="{imdb_logo}" alt="IMDb" style="width: 40px; height: auto;"/>
36
+ <p>{movie['IMDb']}</p>
37
+ </div>
38
+ <div style="text-align: center;">
39
+ <img src="{rotten_logo}" alt="Rotten Tomatoes" style="width: 40px; height: auto;"/>
40
+ <p>{movie['Rotten Tomatoes']}</p>
41
+ </div>
42
+ <div style="text-align: center;">
43
+ <img src="{metacritic_logo}" alt="Metascore" style="width: 40px; height: auto;"/>
44
+ <p>{movie['Metascore']}</p>
45
+ </div>
46
+ </div>
47
+ """,
48
+ "details": f"""
49
+ **Year:** {movie['Year']}
50
+ **Rated:** {movie['Rated']}
51
+ **Runtime:** {movie['Runtime']}
52
+ **Genre:** {movie['Genre1']}, {movie['Genre2']}, {movie['Genre3']}
53
+ **Director:** {movie['Director']}
54
+ **Writer:** {movie['Writer']}
55
+ **Plot:** {movie['Plot']}
56
+ **Awards:** {movie['Awards']}
57
+ **Box Office:** {movie['BoxOffice']}
58
+ """
59
+ }
60
+ return details["title"], details["poster_placeholder"], details["ratings"], details["details"]
61
+
62
+ # Define Gradio interface
63
+ with gr.Blocks() as app:
64
+ gr.Markdown("## 🎬 Movie Database Viewer 🎬")
65
 
66
+ with gr.Row():
67
+ with gr.Column(scale=1):
68
+ poster = gr.Markdown("πŸŽ₯ Movie Poster Placeholder πŸŽ₯", elem_id="poster")
69
+ with gr.Column(scale=2):
70
+ title = gr.Markdown("# Title Placeholder", elem_id="title")
71
+ ratings = gr.HTML("<div style='text-align: center;'>Ratings Placeholder</div>", elem_id="ratings")
72
+ movie_details = gr.Markdown("Details will appear here.", elem_id="details")
73
+
74
+ with gr.Row():
75
+ prev_button = gr.Button("⬅️ Previous")
76
+ next_button = gr.Button("Next ➑️")
77
+
78
+ # Interactivity for buttons
79
+ prev_button.click(
80
+ display_movie,
81
+ inputs=gr.Text(value="prev", visible=False),
82
+ outputs=[title, poster, ratings, movie_details]
83
+ )
84
  next_button.click(
85
+ display_movie,
86
+ inputs=gr.Text(value="next", visible=False),
87
+ outputs=[title, poster, ratings, movie_details]
88
  )
89
 
90
+ # Launch the app
91
  app.launch()
assets/imdblogo.png ADDED
assets/metacritic.png ADDED
assets/rotten.png ADDED