ViBT / app.py
Yuanshi's picture
init
0b31b45
raw
history blame
3.58 kB
import gradio as gr
import spaces
import torch
import os
# ==========================================
# 1. 核心处理函数 (骨架)
# ==========================================
@spaces.GPU
def run_stylization(input_video_path, prompt, noise_scale, shift_gamma, steps, guidance_scale, seed):
"""
这里是实际推理逻辑的占位符。
"""
if not input_video_path:
return None
print("========== Inference Start ==========")
print(f"Video Path: {input_video_path}")
print(f"Prompt: {prompt}")
print(f"Params: Noise={noise_scale}, Gamma={shift_gamma}, Steps={steps}, CFG={guidance_scale}, Seed={seed}")
# [Prototype Logic] 直接返回输入视频用于演示
return input_video_path
# ==========================================
# 2. 界面布局 (Gradio Blocks)
# ==========================================
# 移除 CSS 参数以修复 TypeError
with gr.Blocks() as demo:
with gr.Column(elem_id="col-container"):
gr.Markdown("# 🎥 ViBT Video Stylization Interface")
gr.Markdown("上传视频并设置风格化参数。")
with gr.Row():
# --- 左侧:输入与设置 ---
with gr.Column():
# 视频输入
input_video = gr.Video(label="Source Video", sources=["upload"])
# 提示词
prompt_input = gr.Textbox(
label="Style Prompt",
placeholder="e.g., Van Gogh style, cyberpunk city...",
value="Oil painting style, vivid colors"
)
# 高级参数折叠区
with gr.Accordion("Advanced Settings", open=True):
with gr.Row():
noise_scale = gr.Slider(
label="Noise Scale", minimum=0.0, maximum=2.0, step=0.1, value=1.0,
info="Controls how much noise is added."
)
shift_gamma = gr.Slider(
label="Shift Gamma", minimum=1.0, maximum=10.0, step=0.5, value=5.0,
info="Scheduler parameter."
)
with gr.Row():
num_steps = gr.Slider(
label="Inference Steps", minimum=10, maximum=50, step=1, value=28,
info="More steps = higher quality but slower."
)
guidance_scale = gr.Slider(
label="Guidance Scale (CFG)", minimum=1.0, maximum=20.0, step=0.5, value=1.5,
info="How closely to follow the prompt."
)
seed = gr.Number(label="Seed", value=42, precision=0)
# 提交按钮
run_btn = gr.Button("Generate Video", variant="primary")
# --- 右侧:结果输出 ---
with gr.Column():
output_video = gr.Video(label="Stylized Result", interactive=False)
# ==========================================
# 3. 事件绑定
# ==========================================
run_btn.click(
fn=run_stylization,
inputs=[
input_video,
prompt_input,
noise_scale,
shift_gamma,
num_steps,
guidance_scale,
seed
],
outputs=[output_video]
)
if __name__ == "__main__":
demo.launch()