Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,32 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
import
|
| 4 |
-
import tempfile
|
| 5 |
-
|
| 6 |
-
# 目标保存路径
|
| 7 |
-
SAVE_DIR = "/data/images/images"
|
| 8 |
|
| 9 |
-
|
| 10 |
-
if folder_zip is None:
|
| 11 |
-
return "请上传一个文件夹(打包为 zip 文件)"
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
for root, dirs, files in os.walk(tmpdir):
|
| 19 |
-
for file in files:
|
| 20 |
-
src_file_path = os.path.join(root, file)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
return
|
| 30 |
|
| 31 |
# Gradio 界面
|
| 32 |
demo = gr.Interface(
|
| 33 |
-
fn=
|
| 34 |
-
inputs=
|
| 35 |
outputs="text",
|
| 36 |
-
title="
|
| 37 |
-
description="
|
| 38 |
)
|
| 39 |
|
| 40 |
demo.launch()
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
ROOT_DIR = "/data/images/images"
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def get_directory_structure(root_path):
|
| 7 |
+
if not os.path.exists(root_path):
|
| 8 |
+
return f"路径不存在:{root_path}"
|
| 9 |
|
| 10 |
+
tree_lines = []
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
for current_dir, subdirs, files in os.walk(root_path):
|
| 13 |
+
level = current_dir.replace(root_path, "").count(os.sep)
|
| 14 |
+
indent = " " * level
|
| 15 |
+
tree_lines.append(f"{indent}📁 {os.path.basename(current_dir) or '/'}")
|
| 16 |
|
| 17 |
+
sub_indent = " " * (level + 1)
|
| 18 |
+
for f in files:
|
| 19 |
+
tree_lines.append(f"{sub_indent}📄 {f}")
|
| 20 |
|
| 21 |
+
return "\n".join(tree_lines)
|
| 22 |
|
| 23 |
# Gradio 界面
|
| 24 |
demo = gr.Interface(
|
| 25 |
+
fn=lambda: get_directory_structure(ROOT_DIR),
|
| 26 |
+
inputs=[],
|
| 27 |
outputs="text",
|
| 28 |
+
title="查看 /data/images/images 的目录结构",
|
| 29 |
+
description="点击按钮以展示该目录下的文件夹和文件结构"
|
| 30 |
)
|
| 31 |
|
| 32 |
demo.launch()
|