Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,26 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
with gr.Blocks() as demo:
|
4 |
-
gr.FileExplorer()
|
|
|
5 |
|
6 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
import random
|
4 |
+
import string
|
5 |
+
|
6 |
+
def generate_random_string(length=100):
|
7 |
+
"""Generate a random string of fixed length."""
|
8 |
+
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
|
9 |
+
|
10 |
+
def create_random_text_files(directory, num_files=10, file_length=1000):
|
11 |
+
"""Create specified number of random text files with random content."""
|
12 |
+
if not os.path.exists(directory):
|
13 |
+
os.makedirs(directory)
|
14 |
+
|
15 |
+
for i in range(num_files):
|
16 |
+
file_name = os.path.join(directory, f'random_file_{i}.txt')
|
17 |
+
with open(file_name, 'w') as f:
|
18 |
+
for _ in range(file_length):
|
19 |
+
f.write(generate_random_string() + '\n')
|
20 |
+
|
21 |
|
22 |
with gr.Blocks() as demo:
|
23 |
+
gr.FileExplorer("/data/**.*")
|
24 |
+
demo.load(create_random_text_files, None, None)
|
25 |
|
26 |
demo.launch()
|