Spaces:
Sleeping
Sleeping
env_setup
Browse files- app.py +74 -4
- packages.txt +5 -0
- phantom +1 -0
- requirements.txt +5 -0
- setup.sh +81 -0
app.py
CHANGED
|
@@ -1,7 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Phantom Video Processor - Hugging Face Space
|
| 3 |
+
"""
|
| 4 |
import gradio as gr
|
| 5 |
+
import spaces
|
| 6 |
|
| 7 |
+
import subprocess
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
|
| 11 |
+
# 配置环境
|
| 12 |
+
def setup_environment():
|
| 13 |
+
setup_script = Path("setup.sh")
|
| 14 |
+
|
| 15 |
+
if setup_script.exists() and not Path("/tmp/phantom_ready").exists():
|
| 16 |
+
print("🔧 首次运行,配置环境...")
|
| 17 |
+
subprocess.run(["bash", str(setup_script)], check=True)
|
| 18 |
+
Path("/tmp/phantom_ready").touch()
|
| 19 |
+
print("✅ 环境配置完成")
|
| 20 |
+
else:
|
| 21 |
+
print("✅ 使用已有环境")
|
| 22 |
+
|
| 23 |
+
# 启动时配置
|
| 24 |
+
setup_environment()
|
| 25 |
+
|
| 26 |
+
@spaces.GPU(duration=120)
|
| 27 |
+
def process_video(video_file, robot_type, target_hand):
|
| 28 |
+
"""处理视频"""
|
| 29 |
+
import torch
|
| 30 |
+
|
| 31 |
+
if video_file is None:
|
| 32 |
+
return None, None, "请先上传视频"
|
| 33 |
+
|
| 34 |
+
# 检查GPU
|
| 35 |
+
if torch.cuda.is_available():
|
| 36 |
+
gpu = torch.cuda.get_device_name(0)
|
| 37 |
+
status = f"✅ GPU: {gpu}\n"
|
| 38 |
+
else:
|
| 39 |
+
status = "⚠️ 未检测到GPU\n"
|
| 40 |
+
|
| 41 |
+
status += f"视频: {video_file}\n"
|
| 42 |
+
status += f"机器人: {robot_type}\n"
|
| 43 |
+
status += f"手部: {target_hand}\n"
|
| 44 |
+
|
| 45 |
+
return None, None, status
|
| 46 |
+
|
| 47 |
+
with gr.Blocks(title="Phantom") as demo:
|
| 48 |
+
gr.Markdown("# 🤖 Phantom - 机器人视频生成器")
|
| 49 |
+
|
| 50 |
+
with gr.Row():
|
| 51 |
+
with gr.Column():
|
| 52 |
+
video_input = gr.Video(label="上传视频")
|
| 53 |
+
robot_type = gr.Dropdown(
|
| 54 |
+
choices=["Panda", "Kinova3", "UR5e"],
|
| 55 |
+
value="Panda",
|
| 56 |
+
label="机器人类型"
|
| 57 |
+
)
|
| 58 |
+
target_hand = gr.Radio(
|
| 59 |
+
choices=["left", "right"],
|
| 60 |
+
value="left",
|
| 61 |
+
label="目标手部"
|
| 62 |
+
)
|
| 63 |
+
btn = gr.Button("开始处理", variant="primary")
|
| 64 |
+
|
| 65 |
+
with gr.Column():
|
| 66 |
+
video_out = gr.Video(label="结果视频")
|
| 67 |
+
data_out = gr.File(label="训练数据")
|
| 68 |
+
status_out = gr.Textbox(label="状态", lines=10)
|
| 69 |
+
|
| 70 |
+
btn.click(
|
| 71 |
+
fn=process_video,
|
| 72 |
+
inputs=[video_input, robot_type, target_hand],
|
| 73 |
+
outputs=[video_out, data_out, status_out]
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
demo.queue().launch()
|
packages.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
| 2 |
+
libgl1-mesa-glx
|
| 3 |
+
libglib2.0-0
|
| 4 |
+
wget
|
| 5 |
+
git
|
phantom
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Subproject commit a8bb81c1bbe6ade129a1f6f0906482f510354a5e
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.44.0
|
| 2 |
+
spaces==0.28.3
|
| 3 |
+
torch==2.1.0
|
| 4 |
+
torchvision==0.16.0
|
| 5 |
+
gdown
|
setup.sh
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
echo "🚀 配置Phantom环境..."
|
| 5 |
+
|
| 6 |
+
cd /home/user/app/phantom
|
| 7 |
+
|
| 8 |
+
# 安装SAM2
|
| 9 |
+
if [ ! -f "/tmp/sam2_installed" ]; then
|
| 10 |
+
echo "📦 安装SAM2..."
|
| 11 |
+
cd submodules/sam2
|
| 12 |
+
pip install -q -e ".[notebooks]"
|
| 13 |
+
touch /tmp/sam2_installed
|
| 14 |
+
fi
|
| 15 |
+
|
| 16 |
+
# 安装HaMeR
|
| 17 |
+
if [ ! -f "/tmp/hamer_installed" ]; then
|
| 18 |
+
echo "📦 安装HaMeR..."
|
| 19 |
+
cd /home/user/app/phantom/submodules/phantom-hamer
|
| 20 |
+
pip install -q -e .[all]
|
| 21 |
+
pip install -q -e third-party/ViTPose
|
| 22 |
+
|
| 23 |
+
# 下载demo数据
|
| 24 |
+
if [ ! -f "_DATA/hamer_demo_data.tar.gz" ]; then
|
| 25 |
+
cd _DATA
|
| 26 |
+
wget -q https://www.cs.utexas.edu/~pavlakos/hamer/data/hamer_demo_data.tar.gz
|
| 27 |
+
tar -xzf hamer_demo_data.tar.gz
|
| 28 |
+
rm hamer_demo_data.tar.gz
|
| 29 |
+
fi
|
| 30 |
+
|
| 31 |
+
touch /tmp/hamer_installed
|
| 32 |
+
fi
|
| 33 |
+
|
| 34 |
+
# 安装mmcv
|
| 35 |
+
if [ ! -f "/tmp/mmcv_installed" ]; then
|
| 36 |
+
echo "📦 安装mmcv..."
|
| 37 |
+
pip install -q mmcv==1.3.9
|
| 38 |
+
pip install -q mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu121/torch2.1/index.html
|
| 39 |
+
touch /tmp/mmcv_installed
|
| 40 |
+
fi
|
| 41 |
+
|
| 42 |
+
# 安装robosuite
|
| 43 |
+
if [ ! -f "/tmp/robosuite_installed" ]; then
|
| 44 |
+
echo "📦 安装robosuite..."
|
| 45 |
+
cd /home/user/app/phantom/submodules/phantom-robosuite
|
| 46 |
+
pip install -q -e .
|
| 47 |
+
touch /tmp/robosuite_installed
|
| 48 |
+
fi
|
| 49 |
+
|
| 50 |
+
# 安装robomimic
|
| 51 |
+
if [ ! -f "/tmp/robomimic_installed" ]; then
|
| 52 |
+
echo "📦 安装robomimic..."
|
| 53 |
+
cd /home/user/app/phantom/submodules/phantom-robomimic
|
| 54 |
+
pip install -q -e .
|
| 55 |
+
touch /tmp/robomimic_installed
|
| 56 |
+
fi
|
| 57 |
+
|
| 58 |
+
# 下载E2FGVI权重
|
| 59 |
+
if [ ! -f "/tmp/e2fgvi_weights" ]; then
|
| 60 |
+
echo "📦 下载E2FGVI权重..."
|
| 61 |
+
cd /home/user/app/phantom/submodules/phantom-E2FGVI/E2FGVI/release_model
|
| 62 |
+
pip install -q gdown
|
| 63 |
+
gdown --fuzzy https://drive.google.com/file/d/10wGdKSUOie0XmCr8SQ2A2FeDe-mfn5w3/view?usp=sharing
|
| 64 |
+
touch /tmp/e2fgvi_weights
|
| 65 |
+
fi
|
| 66 |
+
|
| 67 |
+
# 安装E2FGVI
|
| 68 |
+
if [ ! -f "/tmp/e2fgvi_installed" ]; then
|
| 69 |
+
echo "📦 安装E2FGVI..."
|
| 70 |
+
cd /home/user/app/phantom/submodules/phantom-E2FGVI
|
| 71 |
+
pip install -q -e .
|
| 72 |
+
touch /tmp/e2fgvi_installed
|
| 73 |
+
fi
|
| 74 |
+
|
| 75 |
+
# 安装Phantom主包
|
| 76 |
+
if [ ! -f "/tmp/phantom_installed" ]; then
|
| 77 |
+
echo "📦 安装Phantom..."
|
| 78 |
+
cd /home/user/app/phantom
|
| 79 |
+
pip install -q -e .
|
| 80 |
+
touch /tmp/phantom_installed
|
| 81 |
+
fi
|