gaspar-avit commited on
Commit
d3bc4c5
1 Parent(s): 657d4a2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -177,7 +177,7 @@ def query_summary(text):
177
  return text
178
 
179
 
180
- def query_generate(text, genres):
181
  """
182
  Get image from HuggingFace Inference API
183
  -param text: text to generate image
@@ -185,7 +185,7 @@ def query_generate(text, genres):
185
  """
186
  API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
187
  headers = {"Authorization": f"Bearer {st.secrets['hf_token']}"}
188
- text = 'A movie Poster based on the following synopsis: \"' + text + '\". Style: ' + genres
189
  payload = {"inputs": f"{text}",}
190
 
191
  response = requests.post(API_URL, headers=headers, json=payload)
@@ -210,10 +210,12 @@ def generate_poster(movie_data):
210
  -return: image of generated alternative poster
211
  """
212
 
213
- # Get movie genres
214
  genres = [i['name'] for i in eval(movie_data['genres'].values[0])]
215
  genres_string = ', '.join(genres)
216
 
 
 
217
 
218
  # Get summarization of movie synopsis
219
  st.text("")
@@ -233,7 +235,7 @@ def generate_poster(movie_data):
233
 
234
  # Get image based on synopsis
235
  with st.spinner("Generating poster image..."):
236
- response_content = query_generate(synopsis_sum, genres_string)
237
 
238
  # Show image
239
  try:
@@ -245,6 +247,7 @@ def generate_poster(movie_data):
245
  col1, col2, col3 = st.columns([1, 5, 1])
246
  with col2:
247
  st.image(image, caption="Movie: \"" + movie_data.title.values[0] + "\"")
 
248
 
249
  except:
250
  col1, col2 = st.columns([5, 1])
 
177
  return text
178
 
179
 
180
+ def query_generate(text, genres, year):
181
  """
182
  Get image from HuggingFace Inference API
183
  -param text: text to generate image
 
185
  """
186
  API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
187
  headers = {"Authorization": f"Bearer {st.secrets['hf_token']}"}
188
+ text = 'A movie Poster based on the following synopsis: \"' + text + '\". Style: ' + genres + ', year ' + year
189
  payload = {"inputs": f"{text}",}
190
 
191
  response = requests.post(API_URL, headers=headers, json=payload)
 
210
  -return: image of generated alternative poster
211
  """
212
 
213
+ # Get movie metadata
214
  genres = [i['name'] for i in eval(movie_data['genres'].values[0])]
215
  genres_string = ', '.join(genres)
216
 
217
+ year = movie_data['year'].values[0]
218
+
219
 
220
  # Get summarization of movie synopsis
221
  st.text("")
 
235
 
236
  # Get image based on synopsis
237
  with st.spinner("Generating poster image..."):
238
+ response_content = query_generate(synopsis_sum, genres_string, year)
239
 
240
  # Show image
241
  try:
 
247
  col1, col2, col3 = st.columns([1, 5, 1])
248
  with col2:
249
  st.image(image, caption="Movie: \"" + movie_data.title.values[0] + "\"")
250
+ del image
251
 
252
  except:
253
  col1, col2 = st.columns([5, 1])