Download app.py from AEcreator/LAM3: direct link, hf CLI and curl.
- Browser
- Download file 2.4 kB
-
https://huggingface.co/spaces/AEcreator/LAM3/resolve/main/app.py
- Command line
-
hf download hf://spaces/AEcreator/LAM3/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AEcreator/LAM3/resolve/main/app.py
2.4 kB
| # app.py | |
| import os | |
| import gradio as gr | |
| from pathlib import Path | |
| # ====================== | |
| # 配置区(按需修改路径) | |
| # ====================== | |
| # 根目录:你的所有数据放在这个目录下(相对于 app.py) | |
| DATA_ROOT = Path("../outputs") # 例如:data/exp1/chart1.png, data/results/metrics.jsonl | |
| # 支持的图片格式 | |
| IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".svg"} | |
| # ====================== | |
| # 辅助函数 | |
| # ====================== | |
| def find_files(root: Path, extensions: set): | |
| """递归查找指定后缀的文件""" | |
| files = [] | |
| for ext in extensions: | |
| files.extend(root.rglob(f"*{ext}")) | |
| return sorted(files) | |
| def get_relative_path(file: Path): | |
| """获取相对于 DATA_ROOT 的路径,用于显示""" | |
| try: | |
| return str(file.relative_to(DATA_ROOT)) | |
| except ValueError: | |
| return str(file) | |
| # ====================== | |
| # Gradio 应用 | |
| # ====================== | |
| with gr.Blocks(title="Red Team Experiment Dashboard") as demo: | |
| gr.Markdown("## 🔴 Red Team Attack Results Dashboard") | |
| gr.Markdown(f"All charts and raw data from `{DATA_ROOT}` directory.") | |
| # === 图表展示区 === | |
| image_files = find_files(DATA_ROOT, IMAGE_EXTENSIONS) | |
| if image_files: | |
| gr.Markdown("### 📊 Charts") | |
| # 按父文件夹分组 | |
| folders = {} | |
| for img in image_files: | |
| folder = img.parent | |
| if folder not in folders: | |
| folders[folder] = [] | |
| folders[folder].append(img) | |
| for folder, imgs in folders.items(): | |
| folder_name = get_relative_path(folder) | |
| gr.Markdown(f"#### Folder: `{folder_name}/`") | |
| with gr.Row(): | |
| for img in imgs: | |
| label = get_relative_path(img) | |
| gr.Image(str(img), label=label, interactive=False, height=300) | |
| else: | |
| gr.Markdown("### 📊 Charts\n> No images found.") | |
| # === JSONL 下载区 === | |
| jsonl_files = find_files(DATA_ROOT, {".jsonl"}) | |
| if jsonl_files: | |
| gr.Markdown("### 📥 Raw Data (JSONL)") | |
| for jf in jsonl_files: | |
| rel_path = get_relative_path(jf) | |
| gr.File(value=str(jf), label=rel_path, interactive=False) | |
| else: | |
| gr.Markdown("### 📥 Raw Data (JSONL)\n> No .jsonl files found.") | |
| demo.launch() |