Moiz commited on
Commit
e32be66
·
1 Parent(s): c3e839d

updated movie display

Browse files
Files changed (2) hide show
  1. .DS_Store +0 -0
  2. app.py +21 -18
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
app.py CHANGED
@@ -1,20 +1,24 @@
1
  import gradio as gr
2
  import requests
3
  import csv
 
4
 
5
- # Load movie IDs from CSV file
6
- movie_ids = []
7
- csv_path = "MovieRecommender/imdb_movie_codes.csv"
8
-
9
  try:
10
- with open(csv_path, "r") as csv_file:
11
- reader = csv.reader(csv_file)
12
- movie_ids = [row[0] for row in reader if row] # Assuming movie IDs are in the first column
13
  except FileNotFoundError:
14
- print(f"Error: CSV file not found at {csv_path}")
15
-
16
- # Initialize current movie index
17
- current_movie_index = {"index": 0}
 
 
 
 
 
 
 
18
 
19
  # Function to fetch movie details using the given movie ID
20
  def fetch_movie_info(movie_id):
@@ -39,13 +43,12 @@ def fetch_movie_info(movie_id):
39
  return f"Failed to fetch movie details. HTTP Status Code: {response.status_code}"
40
 
41
  # Function to update movie details for the next movie
42
- def update_movie_details():
43
- if not movie_ids:
44
- return "No Movies", "No Movies", "No Movies", "No Movies", "No Movies", "No Movies"
45
-
46
- current_index = current_movie_index["index"]
47
- movie_id = movie_ids[current_index]
48
- current_movie_index["index"] = (current_index + 1) % len(movie_ids) # Loop back to start
49
  return fetch_movie_info(movie_id)
50
 
51
  # Gradio interface
 
1
  import gradio as gr
2
  import requests
3
  import csv
4
+ import pandas as pd
5
 
6
+ #load csv
 
 
 
7
  try:
8
+ df = pd.read_csv('/Users/moizpro/Desktop/MoviesRecommender/MovieRecommender/imdb_movie_codes.csv')
9
+ print("df loaded..")
 
10
  except FileNotFoundError:
11
+ print(f"Error: CSV file not found at path")
12
+ #access frist movieID
13
+ try:
14
+ # Initialize current movie index
15
+ current_movie_index = 0
16
+ # Assign the first element
17
+ movie_id = df.iloc[current_movie_index, 0]
18
+ # Print the value
19
+ print(movie_id)
20
+ except:
21
+ print("error fetching first element")
22
 
23
  # Function to fetch movie details using the given movie ID
24
  def fetch_movie_info(movie_id):
 
43
  return f"Failed to fetch movie details. HTTP Status Code: {response.status_code}"
44
 
45
  # Function to update movie details for the next movie
46
+ def update_movie_details():
47
+ global current_movie_index
48
+ print(current_movie_index)
49
+ movie_id = df.iloc[current_movie_index, 0]
50
+ print(movie_id)
51
+ current_movie_index = (current_movie_index + 1) % len(df) # Loop back to start
 
52
  return fetch_movie_info(movie_id)
53
 
54
  # Gradio interface