codelion commited on
Commit
f5ef562
·
verified ·
1 Parent(s): a98439b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -303,6 +303,9 @@ def start_feed(user_input, generate_video, current_index, feed_items):
303
  if not user_input.strip():
304
  user_input = "trending"
305
 
 
 
 
306
  # Set loading state
307
  is_loading = True
308
  html_content = generate_html([], False, 0, user_input, is_loading)
@@ -341,19 +344,19 @@ def start_feed(user_input, generate_video, current_index, feed_items):
341
  </div>
342
  """
343
  is_loading = False
344
- return user_input, current_index, feed_items, html_content, share_links, is_loading
345
 
346
  # Set loading state to False and update UI
347
  is_loading = False
348
  html_content = generate_html(feed_items, False, current_index, user_input, is_loading)
349
- return user_input, current_index, feed_items, html_content, share_links, is_loading
350
 
351
  def load_next(user_input, generate_video, current_index, feed_items):
352
  """
353
  Load the next item in the feed.
354
 
355
  Args:
356
- user_input (str): The user's input concept or idea.
357
  generate_video (bool): Whether to generate a video.
358
  current_index (int): The current item index.
359
  feed_items (list): The current list of feed items.
@@ -361,6 +364,12 @@ def load_next(user_input, generate_video, current_index, feed_items):
361
  Returns:
362
  tuple: (current_user_input, current_index, feed_items, html_content, share_links, is_loading)
363
  """
 
 
 
 
 
 
364
  is_loading = True
365
  html_content = generate_html(feed_items, False, current_index, user_input, is_loading)
366
  share_links = ""
@@ -399,11 +408,11 @@ def load_next(user_input, generate_video, current_index, feed_items):
399
  </div>
400
  """
401
  is_loading = False
402
- return user_input, current_index, feed_items, html_content, share_links, is_loading
403
 
404
  is_loading = False
405
  html_content = generate_html(feed_items, False, current_index, user_input, is_loading)
406
- return user_input, current_index, feed_items, html_content, share_links, is_loading
407
 
408
  def load_previous(user_input, generate_video, current_index, feed_items):
409
  """
@@ -418,6 +427,9 @@ def load_previous(user_input, generate_video, current_index, feed_items):
418
  Returns:
419
  tuple: (current_user_input, current_index, feed_items, html_content, share_links, is_loading)
420
  """
 
 
 
421
  if current_index > 0:
422
  current_index -= 1
423
  html_content = generate_html(feed_items, False, current_index, user_input, False)
@@ -426,7 +438,7 @@ def load_previous(user_input, generate_video, current_index, feed_items):
426
  feed_items[current_index]['video_base64'],
427
  feed_items[current_index]['text']
428
  )
429
- return user_input, current_index, feed_items, html_content, share_links, False
430
 
431
  def generate_share_links(image_base64, video_base64, caption):
432
  """
@@ -812,7 +824,7 @@ with gr.Blocks(
812
  # Handle magic button click to generate next item
813
  magic_button.click(
814
  fn=load_next,
815
- inputs=[current_user_input, generate_video_checkbox, current_index, feed_items],
816
  outputs=[current_user_input, current_index, feed_items, feed_html, share_html, is_loading]
817
  )
818
 
@@ -822,7 +834,7 @@ with gr.Blocks(
822
  # Handle click to go to previous item
823
  previous_button.click(
824
  fn=load_previous,
825
- inputs=[current_user_input, generate_video_checkbox, current_index, feed_items],
826
  outputs=[current_user_input, current_index, feed_items, feed_html, share_html, is_loading]
827
  )
828
 
 
303
  if not user_input.strip():
304
  user_input = "trending"
305
 
306
+ # Update current_user_input with the new user_input
307
+ current_user_input = user_input
308
+
309
  # Set loading state
310
  is_loading = True
311
  html_content = generate_html([], False, 0, user_input, is_loading)
 
344
  </div>
345
  """
346
  is_loading = False
347
+ return current_user_input, current_index, feed_items, html_content, share_links, is_loading
348
 
349
  # Set loading state to False and update UI
350
  is_loading = False
351
  html_content = generate_html(feed_items, False, current_index, user_input, is_loading)
352
+ return current_user_input, current_index, feed_items, html_content, share_links, is_loading
353
 
354
  def load_next(user_input, generate_video, current_index, feed_items):
355
  """
356
  Load the next item in the feed.
357
 
358
  Args:
359
+ user_input (str): The user's input concept or idea (updated from the textbox).
360
  generate_video (bool): Whether to generate a video.
361
  current_index (int): The current item index.
362
  feed_items (list): The current list of feed items.
 
364
  Returns:
365
  tuple: (current_user_input, current_index, feed_items, html_content, share_links, is_loading)
366
  """
367
+ # Update current_user_input with the latest user_input from the textbox
368
+ current_user_input = user_input if user_input.strip() else "trending"
369
+
370
+ # Use current_user_input for generating the next item
371
+ user_input = current_user_input
372
+
373
  is_loading = True
374
  html_content = generate_html(feed_items, False, current_index, user_input, is_loading)
375
  share_links = ""
 
408
  </div>
409
  """
410
  is_loading = False
411
+ return current_user_input, current_index, feed_items, html_content, share_links, is_loading
412
 
413
  is_loading = False
414
  html_content = generate_html(feed_items, False, current_index, user_input, is_loading)
415
+ return current_user_input, current_index, feed_items, html_content, share_links, is_loading
416
 
417
  def load_previous(user_input, generate_video, current_index, feed_items):
418
  """
 
427
  Returns:
428
  tuple: (current_user_input, current_index, feed_items, html_content, share_links, is_loading)
429
  """
430
+ # Update current_user_input with the latest user_input
431
+ current_user_input = user_input if user_input.strip() else "trending"
432
+
433
  if current_index > 0:
434
  current_index -= 1
435
  html_content = generate_html(feed_items, False, current_index, user_input, False)
 
438
  feed_items[current_index]['video_base64'],
439
  feed_items[current_index]['text']
440
  )
441
+ return current_user_input, current_index, feed_items, html_content, share_links, False
442
 
443
  def generate_share_links(image_base64, video_base64, caption):
444
  """
 
824
  # Handle magic button click to generate next item
825
  magic_button.click(
826
  fn=load_next,
827
+ inputs=[user_input, generate_video_checkbox, current_index, feed_items], # Use user_input directly from textbox
828
  outputs=[current_user_input, current_index, feed_items, feed_html, share_html, is_loading]
829
  )
830
 
 
834
  # Handle click to go to previous item
835
  previous_button.click(
836
  fn=load_previous,
837
+ inputs=[user_input, generate_video_checkbox, current_index, feed_items],
838
  outputs=[current_user_input, current_index, feed_items, feed_html, share_html, is_loading]
839
  )
840