ctn8176 commited on
Commit
5bd8a1a
·
verified ·
1 Parent(s): 97b7fcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -43,14 +43,18 @@ def get_movie_info(movie_title):
43
  year = details_data.get("release_date", "Unknown Year")[:4]
44
  genre = ", ".join(genre["name"] for genre in details_data.get("genres", []))
45
  tmdb_link = f"https://www.themoviedb.org/movie/{movie_id}"
 
 
 
 
46
 
47
- return f"Title: {title}, Year: {year}, Genre: {genre}\nFind more info here: {tmdb_link}"
48
 
49
  else:
50
- return "Movie not found"
51
-
52
  except Exception as e:
53
- return f"Error: {e}"
54
 
55
  def generate_response(prompt):
56
  input_text_template = (
@@ -61,7 +65,7 @@ def generate_response(prompt):
61
  )
62
 
63
  # Call the get_movie_info function to enrich the response
64
- movie_info = get_movie_info(prompt)
65
 
66
  # Concatenate the movie info with the input template
67
  input_text_template += f" Movie Info: {movie_info}"
@@ -79,8 +83,9 @@ def generate_response(prompt):
79
  output = model.generate(**model_inputs, **gen_conf)
80
 
81
  generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
82
- return f"Movie Info:\n{movie_info}\n\nGenerated Response:\n{generated_text}"
83
 
84
  # Create Gradio Interface
85
- iface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
86
  iface.launch()
 
 
43
  year = details_data.get("release_date", "Unknown Year")[:4]
44
  genre = ", ".join(genre["name"] for genre in details_data.get("genres", []))
45
  tmdb_link = f"https://www.themoviedb.org/movie/{movie_id}"
46
+ poster_path = details_data.get("poster_path")
47
+
48
+ # Convert poster_path to a complete image URL
49
+ image_url = f"https://image.tmdb.org/t/p/w500{poster_path}" if poster_path else ""
50
 
51
+ return f"Title: {title}, Year: {year}, Genre: {genre}\nFind more info here: {tmdb_link}", image_url
52
 
53
  else:
54
+ return "Movie not found", ""
55
+
56
  except Exception as e:
57
+ return f"Error: {e}", ""
58
 
59
  def generate_response(prompt):
60
  input_text_template = (
 
65
  )
66
 
67
  # Call the get_movie_info function to enrich the response
68
+ movie_info, image_url = get_movie_info(prompt)
69
 
70
  # Concatenate the movie info with the input template
71
  input_text_template += f" Movie Info: {movie_info}"
 
83
  output = model.generate(**model_inputs, **gen_conf)
84
 
85
  generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
86
+ return f"Movie Info:\n{movie_info}\n\nGenerated Response:\n{generated_text}", image_url
87
 
88
  # Create Gradio Interface
89
+ iface = gr.Interface(fn=generate_response, inputs="text", outputs=["text", "image"])
90
  iface.launch()
91
+