Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,68 +2,16 @@ import gradio as gr
|
|
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()
|
41 |
|
42 |
|
43 |
def saveFile(file):
|
44 |
with open(file.name, "rb") as rfile:
|
45 |
file_infor = fileManager.saveFile(rfile.read(), file.orig_name)
|
46 |
-
return f"https://
|
47 |
|
48 |
|
49 |
nxapp = gr.Interface(fn=saveFile, inputs="file", outputs="text")
|
50 |
-
nxapp.launch()
|
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()"""
|
57 |
-
|
58 |
-
with gr.Blocks() as demo:
|
59 |
-
# File explorer for working directory
|
60 |
-
working_dir = gr.FileExplorer(label="Working directory")
|
61 |
-
|
62 |
-
# File explorer with persistent storage (optional)
|
63 |
-
persistent_storage = gr.FileExplorer(root="/home/user/app", label="Persistent storage")
|
64 |
-
|
65 |
-
# Connect file explorer output to saveFile function input
|
66 |
-
demo.launch(fn=saveFile, inputs=working_dir.outputs, outputs="text")
|
67 |
-
|
68 |
-
# Optionally, if you want to use persistent storage:
|
69 |
-
# demo.launch(fn=saveFile, inputs=[working_dir.outputs, persistent_storage.outputs], outputs="text")
|
|
|
2 |
from uuid import uuid4
|
3 |
from fileManager import FileManager
|
4 |
import re
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
fileManager = FileManager()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
fileManager.start()
|
8 |
|
9 |
|
10 |
def saveFile(file):
|
11 |
with open(file.name, "rb") as rfile:
|
12 |
file_infor = fileManager.saveFile(rfile.read(), file.orig_name)
|
13 |
+
return f"https://astraos-nx-storage.hf.space/file=./{file_infor['path']}"
|
14 |
|
15 |
|
16 |
nxapp = gr.Interface(fn=saveFile, inputs="file", outputs="text")
|
17 |
+
nxapp.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|