Text2Video Huggingface Pipeline 文生视频接口和文生视频论文API

1. 背景

文生视频是AI领域热点,国内外有非常多的优秀产品如Runway AI、Pika AI、可灵King AI、通义千问、智谱的文生视频模型等等。很多文生视频的大模型都是基于Huggingface的 diffusers的python包来开发。为了方便调用,也尝试了使用 PyPI的text2video的python库的Wrapper类进行调用,下面会给大家介绍一下Huggingface Text to Video Pipeline的调用方式
以及使用通用的text2video的python库调用方式。


2. Huggingface Text to Video Pipeline 代码

地址: (https://huggingface.co/docs/diffusers/api/pipelines/text_to_video)

    ## code for huggingface diffusion pipeline

    import torch
    from diffusers import DiffusionPipeline
    from diffusers.utils import export_to_video

    pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16")
    pipe = pipe.to("cuda")

    prompt = "Spiderman is surfing"
    video_frames = pipe(prompt).frames[0]
    video_path = export_to_video(video_frames)
    video_path


3. 使用Python的包Text2Video来下载最新的文本生成领域论文。

3.1 安装 pip3的 text2video的包

 pip install text2video


3.2. 使用现有接口从 arxiv程序化下载最新文生视频的论文

定义输入接口,我们使用的是查询 ArxivPaper的API,需要传入 api_name 字段。同时可以设置 查询接口的 额外属性,包含拓展参数有。

字段|默认值|含义

start| 0|开始entry个数
max_results| 10 | 结束entry个数
sortBy| lastUpdatedDate| 日期字段
sortOrder| descending| 升序或者降序

调用python的 text2video包下载最新发布在 Arxiv论文信息

import text2video as t2v
import json 

input_dict = {"text": "Text to Video"}

res = t2v.api(input_dict, model=None, api_name="ArxivPaperAPI", start=0, max_results = 3)
paper_list = json.loads(res["text"])
print ("###### Text to Image Recent Paper List:")
for (i, paper_json) in enumerate(paper_list):
    print ("|" + paper_json["id"] + "|" + paper_json["title"].replace("\n", "") + "|" + paper_json["updated"] )


输出结果

###### Text to Image Recent Paper List:
|http://arxiv.org/abs/2410.08211v1|LatteCLIP: Unsupervised CLIP Fine-Tuning via LMM-Synthetic Texts|2024-10-10T17:59:59Z
|http://arxiv.org/abs/2410.08210v1|PointOBB-v2: Towards Simpler, Faster, and Stronger Single Point  Supervised Oriented Object Detection|2024-10-10T17:59:56Z
|http://arxiv.org/abs/2410.08209v1|Emerging Pixel Grounding in Large Multimodal Models Without Grounding  Supervision|2024-10-10T17:59:55Z


3.3 自定义接口实现text2Video的API Wrapper

 
继承类 BaseAPI


入参

字段|类型|含义

input_dict| 字典| 处理API输入 text,image,audio,video字段
model| Huggingface的模型 Pytorch
kwargs| 额外参数

出参

output_dict| 字典| API输出的结果的dict,包含4个key text,image,audio,video字段


核心逻辑

model继承自 H

### 关于 DeepSeek 的文生视频功能 DeepSeek 是一种强大的大语言模型,主要专注于文本成任务,但在某些扩展应用场景中也可以通过与其他工具和技术集成来实现更复杂的功能,比如从文本到视频成 (text-to-video generation)[^1]。然而需要注意的是,DeepSeek 官方并未直接提供专门针对文生视频的功能模块。如果要实现这一目标,则可能需要借助其他开源项目或者第三方服务完成整个流程。 以下是基于现有技术和理论框架下的一种解决方案: #### 方法概述 可以采用分阶段的方式构建一个完整的 pipeline 来达成 Text-To-Video Generation 的需求。具体来说,先由 DeepSeek 负责高质量的文字描述输出作为输入素材;再利用预训练好的图像成模型(例如 Stable Diffusion 或 DALL·E),将这些文字转化为静态画面帧序列;最后调用专业的动画合成引擎(如 RunwayML 或 VideoLAN)把这些连续的画面拼接起来形成最终动态影像文件[^2]。 ```python from deepseek import generate_text from diffusers import DiffusionPipeline import cv2 def create_video_from_text(prompt, num_frames=30): # Step 1: Generate descriptive sentences using DeepSeek. descriptions = [generate_text(prompt) for _ in range(num_frames)] # Initialize diffusion model once outside loop to save time/resources. pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5") frames = [] for desc in descriptions: image = pipe(desc).images[0] frame = np.array(image) frames.append(frame) height, width, layers = frames[0].shape video_writer = cv2.VideoWriter('output.mp4',cv2.VideoWriter_fourcc(*'mp4v'), 1, (width,height)) for f in frames: video_writer.write(f) video_writer.release() ``` 以上代码片段展示了如何串联不同组件创建简易版本的 text-to-video generator 。其中 `generate_text` 函数代表调用了 DeepSeek API 获取相应长度连贯性的自然语句串列;而 `DiffusionPipeline` 则是从 Hugging Face Hub 加载指定类型的扩散网络实例化对象用于后续渲染工作[^3]。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值