Moiz commited on
Commit
90326d2
·
1 Parent(s): 8ac4279

movie display

Browse files
Files changed (1) hide show
  1. app.py +25 -18
app.py CHANGED
@@ -1,20 +1,31 @@
1
  import gradio as gr
2
  import requests
3
 
4
- # Function to fetch movie details and handle rating
5
- def fetch_and_rate_movie(movie_id, rating):
6
  api_key = "f2443b04"
7
- url = f"http://www.omdbapi.com/?apikey={api_key}&i={movie_id}"
 
8
  response = requests.get(url)
9
 
10
  if response.status_code == 200:
11
  movie_data = response.json()
12
  if movie_data.get("Response") == "True":
13
- movie_title = movie_data.get("Title", "Unknown Movie")
14
- if rating == "N/A":
15
- return f"You haven't watched '{movie_title}' yet."
16
- else:
17
- return f"You rated '{movie_title}' a {rating}/10."
 
 
 
 
 
 
 
 
 
 
18
  else:
19
  return f"Error: {movie_data.get('Error', 'Movie not found.')}"
20
  else:
@@ -22,17 +33,13 @@ def fetch_and_rate_movie(movie_id, rating):
22
 
23
  # Gradio interface
24
  with gr.Blocks(css="styles.css") as app:
25
- gr.Markdown("# Movie Rating App")
26
- movie_id = gr.Textbox(label="Movie ID", placeholder="Enter the movie ID (e.g., tt1305806)...")
27
- rating = gr.Slider(
28
- minimum=0,
29
- maximum=10,
30
- step=0.25,
31
- elem_id="custom-slider" # Add a custom ID
32
  )
33
- submit = gr.Button("Submit Rating")
34
- output = gr.Textbox(label="Your Feedback")
35
 
36
- submit.click(fetch_and_rate_movie, inputs=[movie_id, rating], outputs=output)
 
37
 
38
  app.launch()
 
1
  import gradio as gr
2
  import requests
3
 
4
+ # Function to fetch movie details using the fixed movieID
5
+ def fetch_movie_info():
6
  api_key = "f2443b04"
7
+ movie_id = "tt1305806" # Fixed movie ID
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:
12
  movie_data = response.json()
13
  if movie_data.get("Response") == "True":
14
+ title = movie_data.get("Title", "N/A")
15
+ year = movie_data.get("Year", "N/A")
16
+ plot = movie_data.get("Plot", "N/A")
17
+ imdb_rating = movie_data.get("imdbRating", "N/A")
18
+ box_office = movie_data.get("BoxOffice", "N/A")
19
+ genre = movie_data.get("Genre", "N/A")
20
+
21
+ return (
22
+ f"**Title:** {title}\n"
23
+ f"**Year:** {year}\n"
24
+ f"**Genre:** {genre}\n"
25
+ f"**Plot:** {plot}\n"
26
+ f"**IMDb Rating:** {imdb_rating}/10\n"
27
+ f"**Box Office:** {box_office}\n"
28
+ )
29
  else:
30
  return f"Error: {movie_data.get('Error', 'Movie not found.')}"
31
  else:
 
33
 
34
  # Gradio interface
35
  with gr.Blocks(css="styles.css") as app:
36
+ gr.Markdown("# Movie Information Display")
37
+ gr.Markdown(
38
+ "This app automatically fetches and displays information about the movie: *The Secret in Their Eyes*."
 
 
 
 
39
  )
40
+ output = gr.Textbox(label="Movie Details", lines=10)
 
41
 
42
+ # Automatically populate the textbox when the app starts
43
+ output.update(value=fetch_movie_info())
44
 
45
  app.launch()