File size: 831 Bytes
e815fc8
6799d2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e815fc8
 
6799d2e
 
e815fc8
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()