跳转到主要内容

使用流程

基于预定义特效的图片生成是一个异步过程,包含以下步骤:
  1. 创建特效场景生成任务 :使用指定的 scene 以及要填充的信息,提交任务,并接收任务ID,字段名为uuid
  2. 检查任务状态 :使用 uuid 轮询任务状态。 状态转换过程:created(已创建)—> pending(待处理)—> processing(处理中)—> completed(完成);如果失败会返回为failed(失败);
  3. 获取特效图像:当任务成功完成,可通过结果响应中的 live_poster_url 获取视频,并下载保存。

示例代码

示例代码

import time
import requests

bearer_token = "jenius_bearer_token" ## 可在 Jenius 账户管理>接口密钥 中查看
headers = {"Authorization": f"Bearer {bearer_token}"}

# --- Step 1: Submit a poster generation task ---
# This function calls the API to start an asynchronous template-based poster generation task.
# Upon success, the API immediately returns a task_id for querying task status.
def make_poster_task() -> str:
    """Submit a template-based poster generation task and return the task ID"""
    url = "https://www.jenius.cn/api/plugins/poster/tasks"
    payload = {        
        "prompt": "youqian",   # pls check "图像特效生成参考列表" for more selection 
        "image_url": "https://example.com/user-photo.jpg",                
    }
    response = requests.post(url, headers=headers, json=payload)
    response.raise_for_status()
    task_id = response.json()["data"]["uuid"]
    return task_id

# --- Step 2: Poll task status ---
# Since poster generation is asynchronous, you need to check status periodically using task_id.
# Once status becomes "completed", the function returns the final URL; if failed, an exception is raised.
def query_task_status(task_id: str):
    url = "https://www.jenius.cn/api/plugins/poster/tasks/{task_id}"    
    while True:
        # A reasonable polling interval is recommended to avoid excessive requests.
        time.sleep(10)
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        response_json = response.json()["data"]
        status = response_json["status"]
        print(f"Current task status: {status}")
        if status == "completed":
            return response_json["live_poster_url"]
        elif status == "failed":
            raise Exception(f"Poster generation failed: {response_json}")

# --- Step 3: Save the poster file ---
# This helper function downloads the generated poster from the provided URL and saves it locally.
def save_from_url(poster_url: str):
    print(f"Downloading poster file from {poster_url}...")
    response = requests.get(poster_url)
    response.raise_for_status()
    with open("output.mp4", "wb") as f:
        f.write(response.content)
    print("Poster successfully saved as output.mp4")

# --- Main process: Full workflow ---
# Execute the entire flow in the order: submit -> poll -> save.
if __name__ == "__main__":
    task_id = make_poster_task()
    print(f"Poster generation task submitted successfully, task_id: {task_id}")
    final_poster_url = query_task_status(task_id)
    print(f"Task completed successfully, poster URL: {final_poster_url}")
    save_from_url(final_poster_url)

图像特效生成参考列表

这里列出了 Jenius 支持的图像特效场景,包括场景名称、功能说明,以及生成的样例。
样例展示prompt场景名称场景说明上传文件输入文本
youqian春节复古喜庆风格上传人物图片,即可生成人物立于贴春联的大门下、双手持红色福字的春节喜庆画面。必填-
zhongming红金骏马新年风格上传人物图片,即可生成人物立于饰有金色纹样的红色骏马前、红金主调质感厚重的新年华贵画面。必填-
anime_cake卡通蛋糕可爱风格上传人物图片,即可生成工笔彩绘风格的人物手捧蛋糕、身穿居家睡衣的可爱画面。必填-
real_cake真人蛋糕生活风格上传人物图片,即可对人物进行高清真人化处理,生成手捧蛋糕、身穿居家睡衣的可爱生活风画面。必填-
firework新年烟花庆祝风格上传人物图片,即可生成人物戴兔耳帽、系棕白条纹围巾、穿星星图案白毛衣、背景为新年烟花的庆祝画面。必填-