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