"""NExT-GPT any-to-any MLLM reproduction - Hugging Face Space entry point. Paper : https://arxiv.org/abs/2309.05519 Code : https://github.com/NExT-GPT/NExT-GPT Weight: https://huggingface.co/ChocoWu/nextgpt_7b_tiva_v0 Deploy: copy this `space/` folder into a Gradio Space. Set the HF_TOKEN secret for lite mode. With no token / no network the offline mode still runs on CPU. """ from __future__ import annotations import os import gradio as gr from pipeline import run MODES = [ ("offline", "Offline(离线占位,CPU 必跑)"), ("lite", "Lite(HF Serverless 推理,需 HF_TOKEN)"), ("full", "Full(检测官方 7b_tiva_v0 权重)"), ] CSS = """ .gradio-container {max-width: 1180px !important;} #signals {font-size: 12px; line-height: 1.7;} footer {display:none !important;} """ def infer(mode_label: str, prompt: str, wanted: list[str], image, audio, video): mode = next(m for m, label in MODES if label == mode_label) r = run(mode, prompt, wanted, image, audio, video) logs = { "mode": r.mode, "pipeline": "ImageBind -> input projection -> Vicuna-7B -> signal tokens -> output projection -> diffusion decoders", "steps": r.log, } return ( r.text, r.image, r.audio, r.video, r.signals, logs, ) with gr.Blocks(title="NExT-GPT · Any-to-Any MLLM 复现", css=CSS) as demo: gr.Markdown( """ # NExT-GPT · Any-to-Any MLLM 复现 文本 / 图像 / 视频 / 音频 **任意输入 → 任意输出**。三段式结构: ImageBind-Huge 编码侧投影 → Vicuna-7B v0 生成文本与**模态信号 token** → 输出投影层驱动 SD v1-5 / ZeroScope v2_576w / AudioLDM-l-full。 > ⚠️ **复现边界**:本 Space 的 `offline` / `lite` 是**接口级复现**(数据流 + 信号 token + 四路输出), > 不加载论文权重。`full` 与提交包 `reproduce/` 目录才是权重级复现(需 ≥1×A100 40GB)。 """ ) with gr.Row(): mode = gr.Radio( choices=[label for _, label in MODES], value=MODES[0][1], label="运行模式", ) wanted = gr.CheckboxGroup( choices=["text", "image", "audio", "video"], value=["text", "image", "audio", "video"], label="请求输出模态", ) prompt = gr.Textbox( label="Prompt", lines=3, value="I started practicing mindfulness recently. Give me a short tip, show me a calming image, play soft music and make a short video.", ) with gr.Accordion("多模态输入(full 模式由 ImageBind 编码;lite/offline 仅记录输入模态)", open=False): with gr.Row(): in_image = gr.Image(type="filepath", label="图像输入") in_audio = gr.Audio(type="filepath", label="音频输入") in_video = gr.Video(label="视频输入") btn = gr.Button("Run any-to-any", variant="primary") with gr.Row(): out_text = gr.Textbox(label="文本输出 / 状态", lines=10) out_image = gr.Image(type="filepath", label="图像输出 (SD v1-5)") with gr.Row(): out_audio = gr.Audio(type="filepath", label="音频输出 (AudioLDM / TTS)") out_video = gr.Video(label="视频输出 (ZeroScope)") with gr.Accordion("模态信号 token(与官方 config/base.yaml 一致:IMG×4 / VID×24 / AUD×8)", open=False): out_signals = gr.Markdown(elem_id="signals") with gr.Accordion("运行日志", open=False): out_log = gr.JSON(label="calls / fallback") gr.Examples( examples=[ ["Explain meditation in two sentences, then generate an image and soft audio.", ["text", "image", "audio"], MODES[0][1]], ["A forest fire near a city; produce a short news video.", ["text", "video"], MODES[0][1]], ], inputs=[prompt, wanted, mode], ) btn.click( fn=infer, inputs=[mode, prompt, wanted, in_image, in_audio, in_video], outputs=[out_text, out_image, out_audio, out_video, out_signals, out_log], ) if __name__ == "__main__": demo.launch( server_name="0.0.0.0", server_port=int(os.getenv("PORT", "7860")), show_api=False, )