Update app.py
Browse files
app.py
CHANGED
@@ -444,6 +444,10 @@ def start_feed(user_input, generate_video, current_index, feed_items):
|
|
444 |
is_loading = True
|
445 |
progress_html = generate_progress_html(0, f"Getting started with {user_input}... π", user_input)
|
446 |
share_links = ""
|
|
|
|
|
|
|
|
|
447 |
|
448 |
try:
|
449 |
# Generate ideas
|
@@ -509,6 +513,10 @@ def load_next(user_input, generate_video, current_index, feed_items):
|
|
509 |
progress_html = generate_progress_html(0, f"Loading next {user_input} vibe... π", user_input)
|
510 |
share_links = ""
|
511 |
|
|
|
|
|
|
|
|
|
512 |
try:
|
513 |
if current_index + 1 < len(feed_items):
|
514 |
current_index += 1
|
@@ -572,13 +580,17 @@ def load_previous(user_input, generate_video, current_index, feed_items):
|
|
572 |
"""
|
573 |
current_user_input = user_input if user_input.strip() else "trending"
|
574 |
|
|
|
|
|
|
|
|
|
575 |
if current_index > 0:
|
576 |
current_index -= 1
|
577 |
feed_html = generate_html(feed_items, False, current_index, user_input, is_loading=False)
|
578 |
share_links = generate_share_links(
|
579 |
-
feed_items[current_index]['image_base64'],
|
580 |
-
feed_items[current_index]['video_base64'],
|
581 |
-
feed_items[current_index]['text']
|
582 |
)
|
583 |
return current_user_input, current_index, feed_items, feed_html, share_links, False, ""
|
584 |
|
@@ -586,8 +598,8 @@ def generate_share_links(image_base64, video_base64, caption):
|
|
586 |
"""
|
587 |
Generate share links for social media platforms with download links for image and video.
|
588 |
"""
|
589 |
-
image_data_url = f"data:image/png;base64,{image_base64}"
|
590 |
-
encoded_caption = urllib.parse.quote(caption)
|
591 |
|
592 |
download_links = f"""
|
593 |
<p style="text-align: center; margin-bottom: 10px;">Download the media to share:</p>
|
@@ -614,7 +626,7 @@ def generate_share_links(image_base64, video_base64, caption):
|
|
614 |
text-decoration: none;
|
615 |
font-size: 14px;
|
616 |
font-weight: bold;
|
617 |
-
|
618 |
" onmouseover="this.style.backgroundColor='#45a049'" onmouseout="this.style.backgroundColor='#4CAF50'">Download Video</a>
|
619 |
"""
|
620 |
download_links += "</div>"
|
@@ -728,6 +740,10 @@ def generate_html(feed_items, scroll_to_latest=False, current_index=0, user_inpu
|
|
728 |
"""
|
729 |
Generate an HTML string to display the current feed item or loading state.
|
730 |
"""
|
|
|
|
|
|
|
|
|
731 |
if is_loading:
|
732 |
return """
|
733 |
<div id="feed-container" style="
|
@@ -864,7 +880,7 @@ with gr.Blocks(
|
|
864 |
) as demo:
|
865 |
current_user_input = gr.State(value="")
|
866 |
current_index = gr.State(value=0)
|
867 |
-
feed_items = gr.State(value=[])
|
868 |
is_loading = gr.State(value=False)
|
869 |
share_links = gr.State(value="")
|
870 |
|
|
|
444 |
is_loading = True
|
445 |
progress_html = generate_progress_html(0, f"Getting started with {user_input}... π", user_input)
|
446 |
share_links = ""
|
447 |
+
|
448 |
+
# Ensure feed_items is a list
|
449 |
+
feed_items = feed_items if isinstance(feed_items, list) else []
|
450 |
+
print(f"start_feed: feed_items type={type(feed_items)}, value={feed_items}")
|
451 |
|
452 |
try:
|
453 |
# Generate ideas
|
|
|
513 |
progress_html = generate_progress_html(0, f"Loading next {user_input} vibe... π", user_input)
|
514 |
share_links = ""
|
515 |
|
516 |
+
# Ensure feed_items is a list
|
517 |
+
feed_items = feed_items if isinstance(feed_items, list) else []
|
518 |
+
print(f"load_next: feed_items type={type(feed_items)}, value={feed_items}, current_index={current_index}")
|
519 |
+
|
520 |
try:
|
521 |
if current_index + 1 < len(feed_items):
|
522 |
current_index += 1
|
|
|
580 |
"""
|
581 |
current_user_input = user_input if user_input.strip() else "trending"
|
582 |
|
583 |
+
# Ensure feed_items is a list
|
584 |
+
feed_items = feed_items if isinstance(feed_items, list) else []
|
585 |
+
print(f"load_previous: feed_items type={type(feed_items)}, value={feed_items}, current_index={current_index}")
|
586 |
+
|
587 |
if current_index > 0:
|
588 |
current_index -= 1
|
589 |
feed_html = generate_html(feed_items, False, current_index, user_input, is_loading=False)
|
590 |
share_links = generate_share_links(
|
591 |
+
feed_items[current_index]['image_base64'] if feed_items else "",
|
592 |
+
feed_items[current_index]['video_base64'] if feed_items else None,
|
593 |
+
feed_items[current_index]['text'] if feed_items else ""
|
594 |
)
|
595 |
return current_user_input, current_index, feed_items, feed_html, share_links, False, ""
|
596 |
|
|
|
598 |
"""
|
599 |
Generate share links for social media platforms with download links for image and video.
|
600 |
"""
|
601 |
+
image_data_url = f"data:image/png;base64,{image_base64}" if image_base64 else "#"
|
602 |
+
encoded_caption = urllib.parse.quote(caption if caption else "")
|
603 |
|
604 |
download_links = f"""
|
605 |
<p style="text-align: center; margin-bottom: 10px;">Download the media to share:</p>
|
|
|
626 |
text-decoration: none;
|
627 |
font-size: 14px;
|
628 |
font-weight: bold;
|
629 |
+
esperienze transition: background-color 0.3s;
|
630 |
" onmouseover="this.style.backgroundColor='#45a049'" onmouseout="this.style.backgroundColor='#4CAF50'">Download Video</a>
|
631 |
"""
|
632 |
download_links += "</div>"
|
|
|
740 |
"""
|
741 |
Generate an HTML string to display the current feed item or loading state.
|
742 |
"""
|
743 |
+
# Ensure feed_items is a list
|
744 |
+
feed_items = feed_items if isinstance(feed_items, list) else []
|
745 |
+
print(f"generate_html: feed_items type={type(feed_items)}, value={feed_items}, current_index={current_index}")
|
746 |
+
|
747 |
if is_loading:
|
748 |
return """
|
749 |
<div id="feed-container" style="
|
|
|
880 |
) as demo:
|
881 |
current_user_input = gr.State(value="")
|
882 |
current_index = gr.State(value=0)
|
883 |
+
feed_items = gr.State(value=[]) # Ensure initial value is an empty list
|
884 |
is_loading = gr.State(value=False)
|
885 |
share_links = gr.State(value="")
|
886 |
|