Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,38 @@ import tempfile
|
|
3 |
from PIL import Image
|
4 |
import uuid
|
5 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Assuming 'my_directory' is a directory in the current working directory
|
8 |
#directory_name = 'temp_dir'
|
@@ -17,19 +49,6 @@ print(f'GRADIO_TEMP_DIR is = {gradio_temp_dir}')
|
|
17 |
absolute_path1 = os.path.abspath(gradio_temp_dir)
|
18 |
print(f"The absolute path of gradio_temp_dir is = {absolute_path1}")
|
19 |
|
20 |
-
#os.makedirs('/data', exist_ok=True)
|
21 |
-
|
22 |
-
#current_directory = os.getcwd()
|
23 |
-
#print(f'current_directory is = {current_directory}')
|
24 |
-
#new_directory_name = 'temp_dir' #os.environ['GRADIO_TEMP_DIR']
|
25 |
-
|
26 |
-
# Constructing the path to the new directory
|
27 |
-
#new_directory_path = os.path.join(current_directory, new_directory_name)
|
28 |
-
#print(f"The path to the new directory is: {new_directory_path}")
|
29 |
-
|
30 |
-
#os.environ['GRADIO_TEMP_DIR'] = new_directory_path
|
31 |
-
|
32 |
-
######
|
33 |
|
34 |
# Get the path of the system's temporary directory
|
35 |
temp_directory = tempfile.gettempdir()
|
@@ -57,7 +76,7 @@ def create():
|
|
57 |
directory = 'temp_dir'
|
58 |
# List all entries in the directory
|
59 |
entries = os.listdir(directory)
|
60 |
-
print(f"listdir of temp_dir directory = {entries}")
|
61 |
temp_directory_file_list = os.listdir(temp_directory)
|
62 |
print(f'temp_directory_file_list is = {temp_directory_file_list}')
|
63 |
return temp_file.name, temp_directory_file_list
|
@@ -69,9 +88,15 @@ with gr.Blocks(delete_cache=(5,10),
|
|
69 |
inp = gr.Textbox(placeholder="What is your name?")
|
70 |
out = gr.Image(type='filepath')
|
71 |
gr.FileExplorer(root="/data", label="Persistent storage")
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
btn.click(create,inputs=[],outputs=[out, inp])
|
|
|
|
|
74 |
|
75 |
-
#filepath11 = demo.move_resource_to_block_cache('/content/testing/mp333.png')
|
76 |
-
#print(f'filepath11 ^^^^^^= {filepath11}')
|
77 |
demo.launch(debug=False)
|
|
|
3 |
from PIL import Image
|
4 |
import uuid
|
5 |
import os
|
6 |
+
import shutil
|
7 |
+
from pathlib import Path
|
8 |
+
import random
|
9 |
+
|
10 |
+
|
11 |
+
def create_local():
|
12 |
+
length = 100
|
13 |
+
text_string = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
|
14 |
+
#rand_num = random.randint(1, 10000)
|
15 |
+
file_name = os.path.join('temp_dir', f'random_file_1.txt')
|
16 |
+
with open(file_name, 'w') as f:
|
17 |
+
for _ in range(10):
|
18 |
+
f.write(text_string + '\n')
|
19 |
+
|
20 |
+
|
21 |
+
def move():
|
22 |
+
# Get the path of the system's temporary directory
|
23 |
+
temp_directory = tempfile.gettempdir()
|
24 |
+
|
25 |
+
# Specify the path of the file you want to move
|
26 |
+
file_path = '/temp_dir/random_file1.txt'
|
27 |
+
|
28 |
+
# Construct the new path in the temporary directory with the same filename
|
29 |
+
new_path = os.path.join(temp_directory, os.path.basename(file_path))
|
30 |
+
|
31 |
+
print(f'new_path - {new_path}')
|
32 |
+
|
33 |
+
# Move the file
|
34 |
+
shutil.move(file_path, new_path)
|
35 |
+
|
36 |
+
print(f"Moved the file to: {new_path}")
|
37 |
+
|
38 |
|
39 |
# Assuming 'my_directory' is a directory in the current working directory
|
40 |
#directory_name = 'temp_dir'
|
|
|
49 |
absolute_path1 = os.path.abspath(gradio_temp_dir)
|
50 |
print(f"The absolute path of gradio_temp_dir is = {absolute_path1}")
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Get the path of the system's temporary directory
|
54 |
temp_directory = tempfile.gettempdir()
|
|
|
76 |
directory = 'temp_dir'
|
77 |
# List all entries in the directory
|
78 |
entries = os.listdir(directory)
|
79 |
+
#print(f"listdir of temp_dir directory = {entries}")
|
80 |
temp_directory_file_list = os.listdir(temp_directory)
|
81 |
print(f'temp_directory_file_list is = {temp_directory_file_list}')
|
82 |
return temp_file.name, temp_directory_file_list
|
|
|
88 |
inp = gr.Textbox(placeholder="What is your name?")
|
89 |
out = gr.Image(type='filepath')
|
90 |
gr.FileExplorer(root="/data", label="Persistent storage")
|
91 |
+
with gr.Row():
|
92 |
+
with gr.Column():
|
93 |
+
btn = gr.Button("Generate temp files!")
|
94 |
+
btn1 = gr.Button("Generate local files!")
|
95 |
+
gr.FileExplorer(label="local storage")
|
96 |
+
btn2 = gr.Button("Move files to temp dir!")
|
97 |
+
|
98 |
btn.click(create,inputs=[],outputs=[out, inp])
|
99 |
+
btn1.click(create_local,inputs=[],outputs=[])
|
100 |
+
btn2.click(move,inputs=[],outputs=[])
|
101 |
|
|
|
|
|
102 |
demo.launch(debug=False)
|