通過用戶輸入文字來生成圖片,
天啟開放平臺:多模態(tài)API接口文檔-以文生圖,輸入文字生成圖片的方式,多模態(tài)api
https://tianqi.aminer.cn/open/document/mm_ref/cogview
和midijouney類似的ai繪畫平臺。
流程圖:
文章來源:http://www.zghlxwxcb.cn/news/detail-565676.html
api 調(diào)用平臺代碼:文章來源地址http://www.zghlxwxcb.cn/news/detail-565676.html
# encoding:utf-8
import requests
import json
import time
'''
cogview
天啟開放平臺:多模態(tài)API接口文檔-以文生圖
https://tianqi.aminer.cn/open/document/mm_ref/cogview
'''
API_KEY = "" # 從控制臺獲取
API_SECRET = "" # 從控制臺獲取
QUERY = "" # 圖片主題
STYLE = "" # 圖片風(fēng)格
request_url = "https://pretrain.aminer.cn/api/v2/"
api = 'cogview'
# 指定請求參數(shù)格式為json
headers = {'Content-Type': 'application/json'}
request_url = request_url + api
data = {
"query": QUERY,
"style": STYLE,
"apikey": API_KEY,
"apisecret": API_SECRET
}
response = requests.post(request_url, headers=headers, data=json.dumps(data))
if response:
print (response.json())
# 返回的response里有task_id,用task_id去請求"https://pretrain.aminer.cn/api/v2/status"接口
'''
請求status接口返回api調(diào)用結(jié)果
'''
task_id = response.json()["result"]["task_id"] # 從之前請求api的結(jié)果中獲取
request_url = 'https://pretrain.aminer.cn/api/v2/status?task_id=' + task_id
response = requests.get(request_url)
if response:
while "output" not in response.json()["result"]:
time.sleep(10)
response = requests.get(request_url)
print(response.json())
到了這里,關(guān)于【多模態(tài)-文字生成圖片】多模態(tài)API接口文檔-以文生圖,輸入文字生成圖片的方式,多模態(tài)api,和midijouney類似的ai繪畫平臺的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!