python调用阿里api实现ai自动排版文字生成海报图片代码
代码语言:python
所属分类:其他
代码描述:python调用阿里api实现ai自动排版文字生成海报图片代码,给他文字标题就能自动排版生成海报图片。
代码标签: python 调用 阿里 api ai 自动 排版 文字 生成 海报 图片 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/local/python3/bin/python3 # -*- coding: utf-8 -* import os import requests import time # 获取环境变量中的 API Key DASHSCOPE_API_KEY ="apikey" # 提交任务的方法 def submit_task(model, title, subtitle, text, image_url, underlay, logo, n=1, temperature=0.7): url = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis' headers = { 'X-DashScope-Async': 'enable', 'Authorization': f'Bearer {DASHSCOPE_API_KEY}', 'Content-Type': 'application/json' } data = { "model": model, "input": { "title": title, "subtitle": subtitle, "text": text, "image_url": image_url, "underlay": underlay, "logo": logo }, "parameters": { "n": n, "temperature": temperature } } try: response = requests.post(url, headers=headers, json=data) response.raise_for_status() return response.json() except requests.RequestException as e: .........完整代码请登录后点击上方下载按钮下载查看
网友评论0