Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from uuid import uuid4
|
3 |
-
from fileManager import FileManager
|
4 |
import re
|
5 |
import os
|
6 |
import random
|
@@ -8,7 +8,7 @@ import string
|
|
8 |
import glob
|
9 |
|
10 |
##############################################################
|
11 |
-
# File
|
12 |
##############################################################
|
13 |
|
14 |
fileManager = FileManager()
|
@@ -22,7 +22,7 @@ def saveFile(file):
|
|
22 |
|
23 |
|
24 |
##############################################################
|
25 |
-
# Random File Generation
|
26 |
##############################################################
|
27 |
|
28 |
def generate_random_string(length=100):
|
@@ -33,10 +33,10 @@ num_files=10
|
|
33 |
file_length=1000
|
34 |
|
35 |
|
36 |
-
def
|
37 |
if not os.path.exists(directory):
|
38 |
return
|
39 |
-
|
40 |
for i in range(num_files):
|
41 |
file_name = os.path.join(directory, f'random_file_{i}.txt')
|
42 |
with open(file_name, 'w') as f:
|
@@ -45,21 +45,25 @@ def generate_random_files(directory):
|
|
45 |
|
46 |
|
47 |
##############################################################
|
48 |
-
# The Gradio App with
|
49 |
##############################################################
|
50 |
|
51 |
with gr.Blocks() as demo:
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
64 |
|
65 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from uuid import uuid4
|
3 |
+
from fileManager import FileManager
|
4 |
import re
|
5 |
import os
|
6 |
import random
|
|
|
8 |
import glob
|
9 |
|
10 |
##############################################################
|
11 |
+
# File Manager Integration
|
12 |
##############################################################
|
13 |
|
14 |
fileManager = FileManager()
|
|
|
22 |
|
23 |
|
24 |
##############################################################
|
25 |
+
# Random Text File Generation Function
|
26 |
##############################################################
|
27 |
|
28 |
def generate_random_string(length=100):
|
|
|
33 |
file_length=1000
|
34 |
|
35 |
|
36 |
+
def generate_text_files(directory):
|
37 |
if not os.path.exists(directory):
|
38 |
return
|
39 |
+
|
40 |
for i in range(num_files):
|
41 |
file_name = os.path.join(directory, f'random_file_{i}.txt')
|
42 |
with open(file_name, 'w') as f:
|
|
|
45 |
|
46 |
|
47 |
##############################################################
|
48 |
+
# The Gradio App with File Management and Text Generation
|
49 |
##############################################################
|
50 |
|
51 |
with gr.Blocks() as demo:
|
52 |
+
|
53 |
+
# File Explorer for Upload (using fileManager integration)
|
54 |
+
gr.File(label="Upload File", upload=True, fn=saveFile)
|
55 |
+
|
56 |
+
# File Explorer for Existing Files (persistent storage)
|
57 |
+
working_dir = gr.FileExplorer(label="Working directory")
|
58 |
+
|
59 |
+
# Generate Random Text Files Button
|
60 |
+
generate_button = gr.Button("Generate Random Text Files")
|
61 |
+
|
62 |
+
@generate_button.click
|
63 |
+
def generate_files(event):
|
64 |
+
# Generate text files in working directory chosen by user
|
65 |
+
generate_text_files(working_dir.value)
|
66 |
+
|
67 |
+
gr.FileExplorer(root=working_dir.value, label="Persistent storage")
|
68 |
|
69 |
demo.launch()
|