leek2 commited on
Commit
6f4239f
1 Parent(s): c3bef02

updated examples

Browse files
Files changed (2) hide show
  1. app.py +20 -3
  2. tools.py +3 -2
app.py CHANGED
@@ -62,6 +62,7 @@ def respond(
62
  openai_chat_history,
63
  min_year,
64
  max_year,
 
65
  ):
66
  '''
67
  :param user_message: string, the user's message
@@ -172,15 +173,31 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
172
  retry_btn = gr.Button('Retry', variant='secondary',)
173
  clear_btn = gr.Button('Clear', variant='secondary')
174
 
 
 
 
175
  # let user pick minimum and maximum year
176
  min_year = gr.Slider(1900, 2024, 1900, label='Min year', interactive=True,)
177
  max_year = gr.Slider(1900, 2024, 2024, label='Max year', interactive=True,)
178
 
 
 
 
 
 
 
 
 
179
  # example inputs
180
  gr.Examples(
181
  [
182
- 'Please recommend some movies with lots of jumpscares or something with lots of blood.. I want to watch some movie that will not let me nor my cousins sleep soundly tonight.',
183
- "Which movie is better? Warrior (2011) or Southpaw (2015)?. I'm looking to watch a boxing movie, and am not sure what to pick between Warrior (2011) or Southpaw (2015). I'm a big fan of both, Jake Gyllenhall and Tom Hardy and honestly just couldn't pick between the two",
 
 
 
 
 
184
  ],
185
  inputs=[input_box],
186
  )
@@ -190,7 +207,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
190
  triggers=[input_box.submit, submit_btn.click],
191
  fn=respond,
192
  api_name='respond',
193
- inputs=[input_box, chatbot, openai_history_state, min_year, max_year,],
194
  outputs=[input_box, chatbot, openai_history_state],
195
  )
196
 
 
62
  openai_chat_history,
63
  min_year,
64
  max_year,
65
+ allowed_movies,
66
  ):
67
  '''
68
  :param user_message: string, the user's message
 
173
  retry_btn = gr.Button('Retry', variant='secondary',)
174
  clear_btn = gr.Button('Clear', variant='secondary')
175
 
176
+ # Filters
177
+ gr.Markdown("<h4 style='margin-left: 1rem'>Filters</h4>")
178
+
179
  # let user pick minimum and maximum year
180
  min_year = gr.Slider(1900, 2024, 1900, label='Min year', interactive=True,)
181
  max_year = gr.Slider(1900, 2024, 2024, label='Max year', interactive=True,)
182
 
183
+ # let user write down a list of movies. results must be a subset of this list
184
+ allowed_movies = gr.Textbox(
185
+ # container=False,
186
+ show_label=True,
187
+ label='Allowed movie list',
188
+ placeholder='Type a list of movies. Result will be a subset of this list.',
189
+ )
190
+
191
  # example inputs
192
  gr.Examples(
193
  [
194
+ # 'Please recommend some movies with lots of jumpscares or something with lots of blood.. I want to watch some movie that will not let me nor my cousins sleep soundly tonight.',
195
+ # "Which movie is better? Warrior (2011) or Southpaw (2015)?. I'm looking to watch a boxing movie, and am not sure what to pick between Warrior (2011) or Southpaw (2015). I'm a big fan of both, Jake Gyllenhall and Tom Hardy and honestly just couldn't pick between the two",
196
+ "What are some good action movies for kids under 10?",
197
+ "I want to watch a film about space travel but not too scientific.",
198
+ "I need a family-friendly movie that deals with environmental themes for an Earth Day event.",
199
+ "Find culturally diverse films for an international film festival at our college.",
200
+ "What are some uplifting movies for a charity fundraiser supporting mental health awareness?",
201
  ],
202
  inputs=[input_box],
203
  )
 
207
  triggers=[input_box.submit, submit_btn.click],
208
  fn=respond,
209
  api_name='respond',
210
+ inputs=[input_box, chatbot, openai_history_state, min_year, max_year, allowed_movies,],
211
  outputs=[input_box, chatbot, openai_history_state],
212
  )
213
 
tools.py CHANGED
@@ -6,12 +6,13 @@ import openai
6
 
7
  openai.api_key = os.environ['OPENAI_API_KEY']
8
 
9
- def get_movie_recs(context, K=5, min_year=1900, max_year=2024,):
 
10
  system_prompt=f"""
11
  Pretend you are a movie recommendation system. I will give you a conversation between a user
12
  and you (a recommender system). Based on the conversation, reply to me with {K} recommendations
13
  without extra sentences. Give the year the movie was released in your response, e.g. Inception (2010).
14
- Give movies that were released between the years {min_year} and {max_year}.
15
  """
16
  user_query=f"Here is the conversation:\n{context}"
17
  response = openai.ChatCompletion.create(
 
6
 
7
  openai.api_key = os.environ['OPENAI_API_KEY']
8
 
9
+ def get_movie_recs(context, K=5, min_year=1900, max_year=2024, allowed_movies=None):
10
+ allow_list = "" if allowed_movies is None else f"Restrict responses to movies in this list: {allowed_movies}."
11
  system_prompt=f"""
12
  Pretend you are a movie recommendation system. I will give you a conversation between a user
13
  and you (a recommender system). Based on the conversation, reply to me with {K} recommendations
14
  without extra sentences. Give the year the movie was released in your response, e.g. Inception (2010).
15
+ Give movies that were released between the years {min_year} and {max_year}. {allow_list}
16
  """
17
  user_query=f"Here is the conversation:\n{context}"
18
  response = openai.ChatCompletion.create(