dynamic gllery
Browse files
app.py
CHANGED
|
@@ -682,37 +682,30 @@ with gr.Blocks(title="AIQuoteClipGenerator - MCP Edition", theme=gr.themes.Soft(
|
|
| 682 |
- π¨ **Multiple Variations:** Get different video styles
|
| 683 |
""")
|
| 684 |
|
| 685 |
-
# Example Gallery -
|
| 686 |
with gr.Accordion("πΈ Example Gallery - Recent Videos", open=True):
|
| 687 |
-
gr.Markdown("See what others have created!
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 694 |
os.makedirs(gallery_output_dir, exist_ok=True)
|
| 695 |
|
| 696 |
-
# Check if there are any existing videos in gallery
|
| 697 |
import glob
|
| 698 |
existing_videos = sorted(glob.glob(f"{gallery_output_dir}/*.mp4"),
|
| 699 |
-
key=os.path.getmtime, reverse=True)[:6]
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
if gallery_videos:
|
| 703 |
-
with gr.Row():
|
| 704 |
-
for video_path in gallery_videos[:3]:
|
| 705 |
-
gr.Video(value=video_path, label="", height=300, show_label=False)
|
| 706 |
-
if len(gallery_videos) > 3:
|
| 707 |
-
with gr.Row():
|
| 708 |
-
for video_path in gallery_videos[3:6]:
|
| 709 |
-
gr.Video(value=video_path, label="", height=300, show_label=False)
|
| 710 |
-
else:
|
| 711 |
-
gr.Markdown("""
|
| 712 |
-
π¬ **No examples yet!** Be the first to generate a video!
|
| 713 |
-
|
| 714 |
-
Your generated videos will appear here for others to see.
|
| 715 |
-
""")
|
| 716 |
|
| 717 |
gr.Markdown("---")
|
| 718 |
gr.Markdown("## π― Generate Your Own Quote Video")
|
|
@@ -798,12 +791,21 @@ with gr.Blocks(title="AIQuoteClipGenerator - MCP Edition", theme=gr.themes.Soft(
|
|
| 798 |
v2 = videos[1] if len(videos) > 1 else None
|
| 799 |
v3 = videos[2] if len(videos) > 2 else None
|
| 800 |
|
| 801 |
-
|
|
|
|
|
|
|
|
|
|
| 802 |
|
| 803 |
generate_btn.click(
|
| 804 |
process_and_display,
|
| 805 |
inputs=[niche, style, num_variations],
|
| 806 |
-
outputs=[output, video1, video2, video3]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 807 |
)
|
| 808 |
|
| 809 |
if __name__ == "__main__":
|
|
|
|
| 682 |
- π¨ **Multiple Variations:** Get different video styles
|
| 683 |
""")
|
| 684 |
|
| 685 |
+
# Example Gallery - Dynamic updates
|
| 686 |
with gr.Accordion("πΈ Example Gallery - Recent Videos", open=True):
|
| 687 |
+
gr.Markdown("See what others have created! Updates automatically after generation.")
|
| 688 |
+
|
| 689 |
+
# Create a Gallery component that can be updated
|
| 690 |
+
gallery_display = gr.Gallery(
|
| 691 |
+
label="Recent Generations",
|
| 692 |
+
show_label=False,
|
| 693 |
+
columns=3,
|
| 694 |
+
rows=2,
|
| 695 |
+
height=400,
|
| 696 |
+
object_fit="contain"
|
| 697 |
+
)
|
| 698 |
+
|
| 699 |
+
# Function to load gallery videos
|
| 700 |
+
def load_gallery_videos():
|
| 701 |
+
gallery_output_dir = "/data/gallery_videos"
|
| 702 |
os.makedirs(gallery_output_dir, exist_ok=True)
|
| 703 |
|
|
|
|
| 704 |
import glob
|
| 705 |
existing_videos = sorted(glob.glob(f"{gallery_output_dir}/*.mp4"),
|
| 706 |
+
key=os.path.getmtime, reverse=True)[:6]
|
| 707 |
+
|
| 708 |
+
return existing_videos if existing_videos else []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 709 |
|
| 710 |
gr.Markdown("---")
|
| 711 |
gr.Markdown("## π― Generate Your Own Quote Video")
|
|
|
|
| 791 |
v2 = videos[1] if len(videos) > 1 else None
|
| 792 |
v3 = videos[2] if len(videos) > 2 else None
|
| 793 |
|
| 794 |
+
# Load updated gallery
|
| 795 |
+
updated_gallery = load_gallery_videos()
|
| 796 |
+
|
| 797 |
+
return status, v1, v2, v3, updated_gallery
|
| 798 |
|
| 799 |
generate_btn.click(
|
| 800 |
process_and_display,
|
| 801 |
inputs=[niche, style, num_variations],
|
| 802 |
+
outputs=[output, video1, video2, video3, gallery_display]
|
| 803 |
+
)
|
| 804 |
+
|
| 805 |
+
# Load gallery on page load
|
| 806 |
+
demo.load(
|
| 807 |
+
load_gallery_videos,
|
| 808 |
+
outputs=[gallery_display]
|
| 809 |
)
|
| 810 |
|
| 811 |
if __name__ == "__main__":
|