abidlabs's picture
abidlabs HF Staff
Update app.py
6799d2e
raw
history blame
831 Bytes
import gradio as gr
import os
import random
import string
def generate_random_string(length=100):
"""Generate a random string of fixed length."""
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
def create_random_text_files(directory, num_files=10, file_length=1000):
"""Create specified number of random text files with random content."""
if not os.path.exists(directory):
os.makedirs(directory)
for i in range(num_files):
file_name = os.path.join(directory, f'random_file_{i}.txt')
with open(file_name, 'w') as f:
for _ in range(file_length):
f.write(generate_random_string() + '\n')
with gr.Blocks() as demo:
gr.FileExplorer("/data/**.*")
demo.load(create_random_text_files, None, None)
demo.launch()