Moiz commited on
Commit
20fd1c8
·
1 Parent(s): 4ae2705

huggingface database

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -1,14 +1,18 @@
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
  # Add a default column for ratings if not already present
9
  for profile in ['moiz', 'udisha', 'musab']:
10
- if profile not in data.columns:
11
- data[profile] = "" # Default rating is empty
12
 
13
  # Save the current index and selected profile
14
  current_index = [0]
@@ -28,13 +32,13 @@ def display_movie(action, profile):
28
  current_profile[0] = profile
29
 
30
  # Update the index based on action
31
- if action == "next" and current_index[0] < len(data) - 1:
32
  current_index[0] += 1
33
  elif action == "prev" and current_index[0] > 0:
34
  current_index[0] -= 1
35
 
36
  # Extract movie details
37
- movie = data.iloc[current_index[0]]
38
 
39
  # Get the IMDb ID from the 'id' column
40
  movie_id = movie.get('id', 'Unknown') # Use 'Unknown' if 'id' doesn't exist
@@ -70,7 +74,7 @@ def display_movie(action, profile):
70
  **Box Office:** {movie['BoxOffice']}
71
  """,
72
  "current_rating": f"Your Rating: {movie[profile]}",
73
- "index_display": f'<span class="index-display">{current_index[0] + 1}/{len(data)}</span>' # Class applied for index
74
  }
75
  return details["title"], details["poster_placeholder"], details["ratings"], details["details"], details["current_rating"], details["index_display"]
76
 
@@ -78,10 +82,11 @@ def submit_rating(rating):
78
  # Update the rating for the current profile and movie
79
  movie_index = current_index[0]
80
  profile = current_profile[0]
81
- data.at[movie_index, profile] = rating
82
 
83
- # Save the changes to the CSV
84
- data.to_csv('MovieDatabase.csv', index=False)
 
85
 
86
  return display_movie("stay", profile)
87
 
@@ -89,10 +94,11 @@ def not_watched():
89
  # Mark the movie as "N/W" for the current profile
90
  movie_index = current_index[0]
91
  profile = current_profile[0]
92
- data.at[movie_index, profile] = "N/W"
93
 
94
- # Save the changes to the CSV
95
- data.to_csv('MovieDatabase.csv', index=False)
 
96
 
97
  return display_movie("stay", profile)
98
 
 
1
  import base64
2
  import gradio as gr
3
  import pandas as pd
4
+ from datasets import Dataset, DatasetDict
5
 
6
+ # Load the dataset from Hugging Face Datasets
7
+ data = Dataset.from_dataset('moizmoizmoizmoiz/MovieRatingDB')
8
+
9
+ # Convert dataset to a pandas DataFrame for easier manipulation
10
+ data_df = data.to_pandas()
11
 
12
  # Add a default column for ratings if not already present
13
  for profile in ['moiz', 'udisha', 'musab']:
14
+ if profile not in data_df.columns:
15
+ data_df[profile] = "" # Default rating is empty
16
 
17
  # Save the current index and selected profile
18
  current_index = [0]
 
32
  current_profile[0] = profile
33
 
34
  # Update the index based on action
35
+ if action == "next" and current_index[0] < len(data_df) - 1:
36
  current_index[0] += 1
37
  elif action == "prev" and current_index[0] > 0:
38
  current_index[0] -= 1
39
 
40
  # Extract movie details
41
+ movie = data_df.iloc[current_index[0]]
42
 
43
  # Get the IMDb ID from the 'id' column
44
  movie_id = movie.get('id', 'Unknown') # Use 'Unknown' if 'id' doesn't exist
 
74
  **Box Office:** {movie['BoxOffice']}
75
  """,
76
  "current_rating": f"Your Rating: {movie[profile]}",
77
+ "index_display": f'<span class="index-display">{current_index[0] + 1}/{len(data_df)}</span>' # Class applied for index
78
  }
79
  return details["title"], details["poster_placeholder"], details["ratings"], details["details"], details["current_rating"], details["index_display"]
80
 
 
82
  # Update the rating for the current profile and movie
83
  movie_index = current_index[0]
84
  profile = current_profile[0]
85
+ data_df.at[movie_index, profile] = rating
86
 
87
+ # Save the changes to the dataset
88
+ updated_data = Dataset.from_pandas(data_df)
89
+ updated_data.push_to_hub("moizmoizmoizmoiz/MovieRatingDB")
90
 
91
  return display_movie("stay", profile)
92
 
 
94
  # Mark the movie as "N/W" for the current profile
95
  movie_index = current_index[0]
96
  profile = current_profile[0]
97
+ data_df.at[movie_index, profile] = "N/W"
98
 
99
+ # Save the changes to the dataset
100
+ updated_data = Dataset.from_pandas(data_df)
101
+ updated_data.push_to_hub("moizmoizmoizmoiz/MovieRatingDB")
102
 
103
  return display_movie("stay", profile)
104