Spaces:
Build error
Build error
| import gradio as gr | |
| import os | |
| import random | |
| import string | |
| import glob | |
| ############################################################## | |
| # Generate some text files and save them in persistent storage | |
| ############################################################## | |
| 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)) | |
| num_files=10 | |
| file_length=1000 | |
| for directory in ["/data", "/data/special"]: | |
| 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') | |
| ############################################################## | |
| # The Gradio app | |
| ############################################################## | |
| with gr.Blocks() as demo: | |
| gr.FileExplorer(label="Working directory") | |
| gr.FileExplorer(root="/data", label="Persistent storage") | |
| demo.launch() |