import os import random import gradio as gr def fake_gan(): base_dir = os.getcwd() # Get the current base directory jpg_files = [file for file in os.listdir(base_dir) if file.lower().endswith((".jpg", ".jpeg"))] # List all files ending with ".jpg" or ".jpeg" images = [(random.choice(jpg_files), os.path.splitext(file)[0]) for file in jpg_files] return images with gr.Blocks() as demo: with gr.Column(variant="panel"): with gr.Row(variant="compact"): text = gr.Textbox( label="Gallery", show_label=False, max_lines=1, placeholder="Enter prompt to filter or leave blank and click for random order", ).style( container=False, ) btn = gr.Button("Generate Gallery").style(full_width=False) gallery = gr.Gallery( label="Generated images", show_label=False, elem_id="gallery" ).style(grid=[2], height="auto") btn.click(fake_gan, None, gallery) if __name__ == "__main__": demo.launch()