Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,3 +15,42 @@ def saveFile(file):
|
|
| 15 |
|
| 16 |
nxapp = gr.Interface(fn=saveFile, inputs="file", outputs="text")
|
| 17 |
nxapp.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
nxapp = gr.Interface(fn=saveFile, inputs="file", outputs="text")
|
| 17 |
nxapp.launch()
|
| 18 |
+
|
| 19 |
+
import gradio as gr
|
| 20 |
+
import os
|
| 21 |
+
import random
|
| 22 |
+
import string
|
| 23 |
+
import glob
|
| 24 |
+
|
| 25 |
+
##############################################################
|
| 26 |
+
# Generate some text files and save them in persistent storage
|
| 27 |
+
##############################################################
|
| 28 |
+
|
| 29 |
+
def generate_random_string(length=100):
|
| 30 |
+
"""Generate a random string of fixed length."""
|
| 31 |
+
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
|
| 32 |
+
|
| 33 |
+
num_files=10
|
| 34 |
+
file_length=1000
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
for directory in ["/home/user/app", "/data"]:
|
| 38 |
+
if not os.path.exists(directory):
|
| 39 |
+
break
|
| 40 |
+
|
| 41 |
+
for i in range(num_files):
|
| 42 |
+
file_name = os.path.join(directory, f'random_file_{i}.txt')
|
| 43 |
+
with open(file_name, 'w') as f:
|
| 44 |
+
for _ in range(file_length):
|
| 45 |
+
f.write(generate_random_string() + '\n')
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
##############################################################
|
| 49 |
+
# The Gradio app
|
| 50 |
+
##############################################################
|
| 51 |
+
|
| 52 |
+
with gr.Blocks() as demo:
|
| 53 |
+
gr.FileExplorer(label="Working directory")
|
| 54 |
+
gr.FileExplorer(root="/home/user/app", label="Persistent storage")
|
| 55 |
+
|
| 56 |
+
demo.launch()
|