Spaces:
Sleeping
Sleeping
Moiz
commited on
Commit
·
b302c0d
1
Parent(s):
30fab7c
next button added
Browse files
app.py
CHANGED
@@ -1,11 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
api_key = "f2443b04"
|
7 |
-
|
8 |
-
url = f"http://www.omdbapi.com/?apikey={api_key}&i={movie_id}&plot=full"
|
9 |
response = requests.get(url)
|
10 |
|
11 |
if response.status_code == 200:
|
@@ -24,22 +38,42 @@ def fetch_movie_info():
|
|
24 |
else:
|
25 |
return f"Failed to fetch movie details. HTTP Status Code: {response.status_code}"
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Gradio interface
|
28 |
with gr.Blocks(css="styles.css") as app:
|
29 |
gr.Markdown("# Movie Information Display")
|
30 |
-
gr.Markdown(
|
31 |
-
"This app automatically fetches and displays information about the movie: *The Secret in Their Eyes*."
|
32 |
-
)
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
43 |
slider = gr.Slider(minimum=0, maximum=10, step=0.25, label="Rating Slider")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
app.launch()
|
|
|
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):
|
21 |
api_key = "f2443b04"
|
22 |
+
url = f"http://www.omdbapi.com/?apikey={api_key}&i={movie_id}"
|
|
|
23 |
response = requests.get(url)
|
24 |
|
25 |
if response.status_code == 200:
|
|
|
38 |
else:
|
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
|
52 |
with gr.Blocks(css="styles.css") as app:
|
53 |
gr.Markdown("# Movie Information Display")
|
54 |
+
gr.Markdown("This app fetches and displays movie information from a list of IMDb movie IDs.")
|
|
|
|
|
55 |
|
56 |
+
# Initial movie details (fetch the first movie)
|
57 |
+
initial_movie_details = update_movie_details()
|
58 |
+
|
59 |
+
title_output = gr.Textbox(label="Title", lines=1, value=initial_movie_details[0])
|
60 |
+
year_output = gr.Textbox(label="Year", lines=1, value=initial_movie_details[1])
|
61 |
+
genre_output = gr.Textbox(label="Genre", lines=1, value=initial_movie_details[2])
|
62 |
+
plot_output = gr.Textbox(label="Plot", lines=5, value=initial_movie_details[3])
|
63 |
+
imdb_rating_output = gr.Textbox(label="IMDb Rating", lines=1, value=initial_movie_details[4])
|
64 |
+
box_office_output = gr.Textbox(label="Box Office", lines=1, value=initial_movie_details[5])
|
65 |
+
|
66 |
+
# Slider for user rating (optional)
|
67 |
slider = gr.Slider(minimum=0, maximum=10, step=0.25, label="Rating Slider")
|
68 |
+
|
69 |
+
# Button to fetch next movie
|
70 |
+
next_button = gr.Button("Next")
|
71 |
+
|
72 |
+
# Action on button click
|
73 |
+
next_button.click(
|
74 |
+
fn=update_movie_details,
|
75 |
+
inputs=[],
|
76 |
+
outputs=[title_output, year_output, genre_output, plot_output, imdb_rating_output, box_office_output]
|
77 |
+
)
|
78 |
|
79 |
app.launch()
|