Spaces:
Sleeping
Sleeping
Moiz
commited on
Commit
Β·
3f6b95e
1
Parent(s):
230d12a
changed to add dynamic index
Browse files
app.py
CHANGED
@@ -3,8 +3,6 @@ import gradio as gr
|
|
3 |
import pandas as pd
|
4 |
from datasets import load_dataset
|
5 |
from datasets import Dataset
|
6 |
-
|
7 |
-
|
8 |
import os
|
9 |
from huggingface_hub import login
|
10 |
|
@@ -14,8 +12,6 @@ hf_token = os.getenv("WRITE_TOKEN")
|
|
14 |
# Authenticate using the secret token
|
15 |
login(token=hf_token)
|
16 |
|
17 |
-
|
18 |
-
|
19 |
# Load the dataset from Hugging Face Datasets
|
20 |
data = load_dataset('moizmoizmoizmoiz/MovieRatingDB', split='train')
|
21 |
|
@@ -95,7 +91,7 @@ def display_movie(action, profile):
|
|
95 |
**Box Office:** {movie['BoxOffice']}
|
96 |
""",
|
97 |
"current_rating": f"Your Rating: {movie[profile]}",
|
98 |
-
"index_display": f'
|
99 |
}
|
100 |
return details["title"], details["poster_content"], details["ratings"], details["details"], details["current_rating"], details["index_display"]
|
101 |
|
@@ -123,18 +119,31 @@ def not_watched():
|
|
123 |
|
124 |
return display_movie("stay", profile)
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
# Define Gradio interface with external CSS file
|
127 |
with gr.Blocks(css_paths="styles.css") as app:
|
128 |
gr.Markdown("## π¬ Movie Database Viewer π¬")
|
129 |
|
130 |
with gr.Row():
|
131 |
-
# Profile selector and movie index
|
132 |
-
|
|
|
|
|
133 |
|
134 |
-
# Adding two blank columns
|
135 |
blank_column_1 = gr.Column(scale=1, elem_id="blank-column-1")
|
136 |
-
blank_column_2 = gr.Column(scale=1, elem_id="blank-column-2")
|
137 |
-
blank_column_3 = gr.Column(scale=1, elem_id="blank-column-3")
|
138 |
|
139 |
profile_selector = gr.Dropdown(
|
140 |
choices=['moiz', 'udisha', 'musab'],
|
@@ -157,50 +166,49 @@ with gr.Blocks(css_paths="styles.css") as app:
|
|
157 |
rating_slider = gr.Slider(0, 10, step=0.25, label="Rate this movie:", elem_id="rating-slider", interactive=True, scale=2)
|
158 |
|
159 |
with gr.Row():
|
160 |
-
|
161 |
not_watched_button = gr.Button("π« Not Watched")
|
162 |
-
|
163 |
blank_column_1 = gr.Column(scale=1, elem_id="blank-column-1")
|
164 |
-
|
165 |
-
|
166 |
submit_button = gr.Button("β
Submit Rating")
|
167 |
|
168 |
with gr.Row():
|
169 |
-
# Two blank columns between previous and next buttons
|
170 |
prev_button = gr.Button("β¬
οΈ Previous", scale=1)
|
171 |
-
|
172 |
blank_column_1 = gr.Column(scale=2, elem_id="blank-column-1")
|
173 |
blank_column_2 = gr.Column(scale=2, elem_id="blank-column-2")
|
174 |
-
|
175 |
next_button = gr.Button("Next β‘οΈ", scale=1)
|
176 |
|
177 |
# Interactivity for buttons
|
178 |
profile_selector.change(
|
179 |
display_movie,
|
180 |
inputs=[gr.Text(value="stay", visible=False), profile_selector],
|
181 |
-
outputs=[title, poster, ratings, movie_details, user_rating,
|
182 |
)
|
183 |
|
184 |
prev_button.click(
|
185 |
display_movie,
|
186 |
inputs=[gr.Text(value="prev", visible=False), profile_selector],
|
187 |
-
outputs=[title, poster, ratings, movie_details, user_rating,
|
188 |
)
|
189 |
next_button.click(
|
190 |
display_movie,
|
191 |
inputs=[gr.Text(value="next", visible=False), profile_selector],
|
192 |
-
outputs=[title, poster, ratings, movie_details, user_rating,
|
193 |
)
|
194 |
|
195 |
submit_button.click(
|
196 |
submit_rating,
|
197 |
inputs=rating_slider,
|
198 |
-
outputs=[title, poster, ratings, movie_details, user_rating,
|
199 |
)
|
200 |
|
201 |
not_watched_button.click(
|
202 |
not_watched,
|
203 |
-
outputs=[title, poster, ratings, movie_details, user_rating,
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
)
|
205 |
|
206 |
app.launch()
|
|
|
3 |
import pandas as pd
|
4 |
from datasets import load_dataset
|
5 |
from datasets import Dataset
|
|
|
|
|
6 |
import os
|
7 |
from huggingface_hub import login
|
8 |
|
|
|
12 |
# Authenticate using the secret token
|
13 |
login(token=hf_token)
|
14 |
|
|
|
|
|
15 |
# Load the dataset from Hugging Face Datasets
|
16 |
data = load_dataset('moizmoizmoizmoiz/MovieRatingDB', split='train')
|
17 |
|
|
|
91 |
**Box Office:** {movie['BoxOffice']}
|
92 |
""",
|
93 |
"current_rating": f"Your Rating: {movie[profile]}",
|
94 |
+
"index_display": f'{current_index[0] + 1}'
|
95 |
}
|
96 |
return details["title"], details["poster_content"], details["ratings"], details["details"], details["current_rating"], details["index_display"]
|
97 |
|
|
|
119 |
|
120 |
return display_movie("stay", profile)
|
121 |
|
122 |
+
def jump_to_index(index, profile):
|
123 |
+
# Ensure the input index is valid
|
124 |
+
try:
|
125 |
+
index = int(index) - 1 # Convert to zero-based index
|
126 |
+
except ValueError:
|
127 |
+
index = current_index[0] # If invalid, keep the current index
|
128 |
+
|
129 |
+
# Update the index only if within range
|
130 |
+
if 0 <= index < len(data_df):
|
131 |
+
current_index[0] = index
|
132 |
+
|
133 |
+
# Display the movie details for the selected index
|
134 |
+
return display_movie("stay", profile)
|
135 |
+
|
136 |
# Define Gradio interface with external CSS file
|
137 |
with gr.Blocks(css_paths="styles.css") as app:
|
138 |
gr.Markdown("## π¬ Movie Database Viewer π¬")
|
139 |
|
140 |
with gr.Row():
|
141 |
+
# Profile selector and movie index
|
142 |
+
movie_index_input = gr.Textbox(
|
143 |
+
value="1", label="Go to Movie Index", interactive=True, elem_id="movie-index-input"
|
144 |
+
)
|
145 |
|
|
|
146 |
blank_column_1 = gr.Column(scale=1, elem_id="blank-column-1")
|
|
|
|
|
147 |
|
148 |
profile_selector = gr.Dropdown(
|
149 |
choices=['moiz', 'udisha', 'musab'],
|
|
|
166 |
rating_slider = gr.Slider(0, 10, step=0.25, label="Rate this movie:", elem_id="rating-slider", interactive=True, scale=2)
|
167 |
|
168 |
with gr.Row():
|
|
|
169 |
not_watched_button = gr.Button("π« Not Watched")
|
|
|
170 |
blank_column_1 = gr.Column(scale=1, elem_id="blank-column-1")
|
|
|
|
|
171 |
submit_button = gr.Button("β
Submit Rating")
|
172 |
|
173 |
with gr.Row():
|
|
|
174 |
prev_button = gr.Button("β¬
οΈ Previous", scale=1)
|
|
|
175 |
blank_column_1 = gr.Column(scale=2, elem_id="blank-column-1")
|
176 |
blank_column_2 = gr.Column(scale=2, elem_id="blank-column-2")
|
|
|
177 |
next_button = gr.Button("Next β‘οΈ", scale=1)
|
178 |
|
179 |
# Interactivity for buttons
|
180 |
profile_selector.change(
|
181 |
display_movie,
|
182 |
inputs=[gr.Text(value="stay", visible=False), profile_selector],
|
183 |
+
outputs=[title, poster, ratings, movie_details, user_rating, movie_index_input]
|
184 |
)
|
185 |
|
186 |
prev_button.click(
|
187 |
display_movie,
|
188 |
inputs=[gr.Text(value="prev", visible=False), profile_selector],
|
189 |
+
outputs=[title, poster, ratings, movie_details, user_rating, movie_index_input]
|
190 |
)
|
191 |
next_button.click(
|
192 |
display_movie,
|
193 |
inputs=[gr.Text(value="next", visible=False), profile_selector],
|
194 |
+
outputs=[title, poster, ratings, movie_details, user_rating, movie_index_input]
|
195 |
)
|
196 |
|
197 |
submit_button.click(
|
198 |
submit_rating,
|
199 |
inputs=rating_slider,
|
200 |
+
outputs=[title, poster, ratings, movie_details, user_rating, movie_index_input]
|
201 |
)
|
202 |
|
203 |
not_watched_button.click(
|
204 |
not_watched,
|
205 |
+
outputs=[title, poster, ratings, movie_details, user_rating, movie_index_input]
|
206 |
+
)
|
207 |
+
|
208 |
+
movie_index_input.submit(
|
209 |
+
jump_to_index,
|
210 |
+
inputs=[movie_index_input, profile_selector],
|
211 |
+
outputs=[title, poster, ratings, movie_details, user_rating, movie_index_input]
|
212 |
)
|
213 |
|
214 |
app.launch()
|