Spaces:
Sleeping
Sleeping
File size: 2,112 Bytes
1db582e af7c474 a924ad2 af7c474 571bda5 1db582e 4e076ab af7c474 1db582e af7c474 c67ad58 737d007 3cb650b 438b1f7 571bda5 4e076ab |
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import gradio as gr
from uuid import uuid4
from fileManager import FileManager
import re
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 ["/home/user/app", "/data"]:
if not os.path.exists(directory):
break
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
##############################################################
"""fileManager = FileManager()
fileManager.start()
def saveFile(file):
with open(file.name, "rb") as rfile:
file_infor = fileManager.saveFile(rfile.read(), file.orig_name)
return f"https://emee-nx-storage.hf.space/file=./{file_infor['path']}"
nxapp = gr.Interface(fn=saveFile, inputs="file", outputs="text")
nxapp.launch()
with gr.Blocks() as demo:
gr.FileExplorer(label="Working directory")
gr.FileExplorer(root="/home/user/app", label="Persistent storage")
demo.launch()"""
with gr.Blocks() as demo:
# File explorer for working directory
working_dir = gr.FileExplorer(label="Working directory")
# File explorer with persistent storage (optional)
persistent_storage = gr.FileExplorer(root="/home/user/app", label="Persistent storage")
# Connect file explorer output to saveFile function input
demo.launch(fn=saveFile, inputs=working_dir.outputs, outputs="text")
# Optionally, if you want to use persistent storage:
# demo.launch(fn=saveFile, inputs=[working_dir.outputs, persistent_storage.outputs], outputs="text") |