Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
# Function to fetch movie details using the fixed movieID | |
def fetch_movie_info(): | |
api_key = "f2443b04" | |
movie_id = "tt1305806" # Fixed movie ID | |
url = f"http://www.omdbapi.com/?apikey={api_key}&i={movie_id}" | |
response = requests.get(url) | |
if response.status_code == 200: | |
movie_data = response.json() | |
if movie_data.get("Response") == "True": | |
title = movie_data.get("Title", "N/A") | |
year = movie_data.get("Year", "N/A") | |
plot = movie_data.get("Plot", "N/A") | |
imdb_rating = movie_data.get("imdbRating", "N/A") | |
box_office = movie_data.get("BoxOffice", "N/A") | |
genre = movie_data.get("Genre", "N/A") | |
return title, year, genre, plot, imdb_rating, box_office | |
else: | |
return "Error", "Error", "Error", "Error", "Error", "Error" | |
else: | |
return f"Failed to fetch movie details. HTTP Status Code: {response.status_code}" | |
# Gradio interface | |
with gr.Blocks(css="styles.css") as app: | |
gr.Markdown("# Movie Information Display") | |
gr.Markdown( | |
"This app automatically fetches and displays information about the movie: *The Secret in Their Eyes*." | |
) | |
# Fetch movie details and display in separate elements | |
title_output = gr.Textbox(label="Title", lines=1, value=fetch_movie_info()[0]) | |
year_output = gr.Textbox(label="Year", lines=1, value=fetch_movie_info()[1]) | |
genre_output = gr.Textbox(label="Genre", lines=1, value=fetch_movie_info()[2]) | |
plot_output = gr.Textbox(label="Plot", lines=5, value=fetch_movie_info()[3]) | |
imdb_rating_output = gr.Textbox(label="IMDb Rating", lines=1, value=fetch_movie_info()[4]) | |
box_office_output = gr.Textbox(label="Box Office", lines=1, value=fetch_movie_info()[5]) | |
# Adding a slider | |
slider = gr.Slider(minimum=0, maximum=10, step=0.25, label="Rating Slider") | |
app.launch() | |