Skip to content

Commit 3849935

Browse files
committed
Update ci sdk
1 parent ea4056f commit 3849935

File tree

3 files changed

+818
-17
lines changed

3 files changed

+818
-17
lines changed

demo/ci_image.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding=utf-8
2+
import json
23
from urllib.parse import quote, urlencode
34

45
from qcloud_cos.cos_comm import to_bytes
@@ -34,6 +35,19 @@
3435
watermark_url_base64 = bytes.decode(base64.b64encode(str.encode(watermark_url)))
3536

3637

38+
def ci_image_inspect():
39+
# 车辆车牌检测
40+
response = client.ci_process(
41+
Bucket=bucket_name,
42+
Key='heichan.png',
43+
CiProcess='ImageInspect'
44+
)
45+
result = json.loads(response)
46+
if result["suspicious"]:
47+
print("ok")
48+
print(response)
49+
50+
3751
def when_put_object(local_file, key, pic_operations):
3852
response, data = client.ci_put_object_from_local_file(
3953
Bucket=bucket_name,
@@ -93,7 +107,8 @@ def add_blind_watermark_process_on_cloud():
93107
process_on_cloud('format.png', operations)
94108

95109

96-
sample_url = 'http://{bucket}.cos.{region}.tencentcos.cn/sample.png'.format(bucket=bucket_name, region=region)
110+
sample_url = 'http://{bucket}.cos.{region}.tencentcos.cn/sample.png'.format(
111+
bucket=bucket_name, region=region)
97112
sample_url_base64 = bytes.decode(base64.b64encode(str.encode(sample_url)))
98113

99114

@@ -337,7 +352,8 @@ def image_watermark_process_on_cloud():
337352
process_on_cloud('format.png', operations)
338353

339354

340-
text_watermark_base64 = bytes.decode(base64.b64encode(str.encode("testWaterMark")))
355+
text_watermark_base64 = bytes.decode(
356+
base64.b64encode(str.encode("testWaterMark")))
341357
text_color_base64 = bytes.decode(base64.b64encode(str.encode("#3D3D3D")))
342358

343359

@@ -658,5 +674,5 @@ def ci_recognize_logo_process():
658674
# ci_get_image_style()
659675
# ci_delete_image_style()
660676
# ci_image_detect_label()
661-
ci_recognize_logo_process()
662-
677+
# ci_recognize_logo_process()
678+
ci_image_inspect()

demo/ci_media.py

Lines changed: 283 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,65 @@ def ci_get_media_queue():
5252
return response
5353

5454

55+
def ci_get_pic_bucket():
56+
# 查询图片处理异步服务开通状态
57+
response = client.ci_get_pic_bucket(
58+
Regions=region,
59+
BucketName='demo',
60+
BucketNames=bucket_name,
61+
PageSize="1",
62+
PageNumber="1"
63+
)
64+
print(response)
65+
return response
66+
67+
68+
def ci_get_ai_bucket():
69+
# 查询ai处理异步服务开通状态
70+
response = client.ci_get_ai_bucket(
71+
Regions=region,
72+
BucketName='demo',
73+
BucketNames=bucket_name,
74+
PageSize="1",
75+
PageNumber="1"
76+
)
77+
print(response)
78+
return response
79+
80+
81+
def ci_get_ai_queue():
82+
# 查询ai处理队列信息
83+
response = client.ci_get_ai_queue(
84+
Bucket=bucket_name,
85+
)
86+
print(response)
87+
return response
88+
89+
90+
def ci_put_ai_queue():
91+
# 更新ai队列信息
92+
body = {
93+
'Name': 'ai-queue',
94+
'QueueID': 'pa2c2afbe68xxxxxxxxxxxxxxxxxxxxxx',
95+
'State': 'Active',
96+
'NotifyConfig': {
97+
'Type': 'Url',
98+
'Url': 'http://www.demo.callback.com',
99+
'Event': 'TaskFinish',
100+
'State': 'On',
101+
'ResultFormat': 'JSON',
102+
}
103+
}
104+
response = client.ci_update_ai_queue(
105+
Bucket=bucket_name,
106+
QueueId='pa2c2afbe68c44xxxxxxxxxxxxxxxxxxxx',
107+
Request=body,
108+
ContentType='application/xml'
109+
)
110+
print(response)
111+
return response
112+
113+
55114
def ci_get_media_pic_queue():
56115
# 查询图片处理队列信息
57116
response = client.ci_get_media_pic_queue(
@@ -72,7 +131,16 @@ def ci_put_media_queue():
72131
'Url': 'http://www.demo.callback.com',
73132
'Event': 'TaskFinish',
74133
'State': 'On',
75-
'ResultFormat': 'JSON'
134+
'ResultFormat': 'JSON',
135+
# TDMQ回调信息配置
136+
# 消息队列所属园区
137+
# 必选。目前支持园区 sh(上海)、bj(北京)、gz(广州)、cd(成都)、hk(中国香港)
138+
# 'MqRegion': 'bj',
139+
# # 消息队列使用模式
140+
# # 必选。主题订阅:Topic 队列服务: Queue
141+
# 'MqMode': 'Queue',
142+
# # TDMQ 主题名称 必选。
143+
# 'MqName': 'queueName'
76144
}
77145
}
78146
response = client.ci_update_media_queue(
@@ -305,6 +373,7 @@ def ci_create_media_transcode_jobs():
305373
'Region': region,
306374
'Object': 'transcode_output.mp4'
307375
},
376+
# 'FreeTranscode': 'true',
308377
# 'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5'
309378
}
310379
}
@@ -1596,6 +1665,25 @@ def ci_create_image_inspect_workflow_batch_jobs():
15961665
return response
15971666

15981667

1668+
def ci_list_inventory_trigger_jobs():
1669+
# 查询批量处理任务列表
1670+
response = client.ci_list_inventory_trigger_jobs(
1671+
Bucket=bucket_name, # 桶名称
1672+
)
1673+
print(response)
1674+
return response
1675+
1676+
1677+
def ci_get_inventory_trigger_jobs():
1678+
# 查询指定批量处理任务
1679+
response = client.ci_get_inventory_trigger_jobs(
1680+
Bucket=bucket_name, # 桶名称
1681+
JobID='bb16331089f7c11ecb10252540019ee59',
1682+
)
1683+
print(response)
1684+
return response
1685+
1686+
15991687
def ci_delete_inventory_trigger_jobs():
16001688
# 删除指定的批量处理任务
16011689
response = client.ci_delete_inventory_trigger_jobs(
@@ -1652,6 +1740,187 @@ def ci_create_sound_hound_jobs():
16521740
return response
16531741

16541742

1743+
def ci_create_noise_reduction_jobs():
1744+
# 创建音频降噪任务
1745+
body = {
1746+
'Input': {
1747+
'Object': 'demo.mp3'
1748+
},
1749+
'Tag': 'NoiseReduction',
1750+
'Operation': {
1751+
'Output': {
1752+
'Bucket': bucket_name,
1753+
'Region': region,
1754+
'Object': 'noise_reduction_result.mp3',
1755+
},
1756+
# 'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5'
1757+
}
1758+
}
1759+
response = client.ci_create_media_jobs(
1760+
Bucket=bucket_name,
1761+
Jobs=body,
1762+
Lst={},
1763+
ContentType='application/xml'
1764+
)
1765+
print(response)
1766+
return response
1767+
1768+
1769+
def ci_create_stream_extract_jobs():
1770+
# 创建流分离任务
1771+
body = {
1772+
'Input': {
1773+
'Object': 'demo.mp4'
1774+
},
1775+
'Tag': 'StreamExtract',
1776+
'Operation': {
1777+
'Output': {
1778+
'Bucket': bucket_name,
1779+
'Region': region,
1780+
'StreamExtract': [
1781+
{
1782+
'Index': '0',
1783+
'Object': 'stream-1.mp4'
1784+
},
1785+
{
1786+
'Index': '1',
1787+
'Object': 'stream-2.mp4'
1788+
}
1789+
]
1790+
},
1791+
}
1792+
}
1793+
response = client.ci_create_media_jobs(
1794+
Bucket=bucket_name,
1795+
Jobs=body,
1796+
Lst={},
1797+
ContentType='application/xml'
1798+
)
1799+
print(response)
1800+
return response
1801+
1802+
1803+
def ci_create_tts_jobs():
1804+
# 创建语音合成任务
1805+
body = {
1806+
'Tag': 'Tts',
1807+
'Input': {
1808+
'Object': 'demo.mp4'
1809+
},
1810+
'Operation': {
1811+
'TtsTpl': {
1812+
# 处理模式,Asyc(异步合成)、Sync(同步合成)
1813+
# 当选择 Asyc 时,codec 只支持 pcm
1814+
# 默认值 Asyc
1815+
'Mode': '',
1816+
# 音频格式,wav、mp3、pcm
1817+
# 默认值 wav(同步)/pcm(异步)
1818+
'Codec': '',
1819+
# 音色
1820+
# 默认值 ruxue
1821+
'VoiceType': '',
1822+
# 音量
1823+
# 取值范围:[-10,10]
1824+
# 默认值0
1825+
'Volume': '',
1826+
# 语速
1827+
# 取值范围:[50,200]
1828+
# 默认值100
1829+
'Speed': '',
1830+
},
1831+
'TemplateId': '',
1832+
'TtsConfig': {
1833+
'InputType': 'Text',
1834+
'Input': '床前明月光,疑是地上霜',
1835+
},
1836+
'Output': {
1837+
'Bucket': bucket_name,
1838+
'Region': region,
1839+
'Object': 'result.mp3'
1840+
},
1841+
}
1842+
}
1843+
response = client.ci_create_media_jobs(
1844+
Bucket=bucket_name,
1845+
Jobs=body,
1846+
Lst={},
1847+
ContentType='application/xml'
1848+
)
1849+
print(response)
1850+
return response
1851+
1852+
1853+
def ci_create_translation_jobs():
1854+
# 创建翻译任务
1855+
body = {
1856+
'Tag': 'Translation',
1857+
'Input': {
1858+
'Object': 'demo.txt',
1859+
'Lang': 'en',
1860+
'Type': 'txt',
1861+
# 'BasicType': ''
1862+
},
1863+
'Operation': {
1864+
'Translation': {
1865+
'Lang': 'zh',
1866+
'Type': 'txt',
1867+
},
1868+
'Output': {
1869+
'Bucket': bucket_name,
1870+
'Region': region,
1871+
'Object': 'result.txt'
1872+
},
1873+
}
1874+
}
1875+
response = client.ci_create_media_jobs(
1876+
Bucket=bucket_name,
1877+
Jobs=body,
1878+
Lst={},
1879+
ContentType='application/xml'
1880+
)
1881+
print(response)
1882+
return response
1883+
1884+
1885+
def ci_create_words_generalize_jobs():
1886+
# 创建分词任务
1887+
body = {
1888+
'Tag': 'WordsGeneralize',
1889+
'Input': {
1890+
'Object': 'demo.txt',
1891+
},
1892+
'Operation': {
1893+
'WordsGeneralize': {
1894+
'NerMethod': 'DL',
1895+
'SegMethod': 'MIX',
1896+
},
1897+
}
1898+
}
1899+
response = client.ci_create_media_jobs(
1900+
Bucket=bucket_name,
1901+
Jobs=body,
1902+
Lst={},
1903+
ContentType='application/xml'
1904+
)
1905+
print(response)
1906+
return response
1907+
1908+
1909+
def ci_get_presigned_download_url():
1910+
param = {
1911+
"object": "test.gif",
1912+
"format": "mp4"
1913+
}
1914+
url = client.get_presigned_download_url(
1915+
Bucket=bucket_name,
1916+
Key='/convert',
1917+
Expired=3600,
1918+
Params=param,
1919+
UseCiEndPoint=True,
1920+
)
1921+
print(url)
1922+
1923+
16551924
if __name__ == "__main__":
16561925
# ci_get_media_queue()
16571926
# ci_get_media_jobs()
@@ -1698,4 +1967,16 @@ def ci_create_sound_hound_jobs():
16981967
# ci_update_workflow_state()
16991968
# ci_delete_workflow()
17001969
# ci_create_image_inspect_jobs()
1701-
ci_create_sound_hound_jobs()
1970+
# ci_create_sound_hound_jobs()
1971+
# ci_list_inventory_trigger_jobs()
1972+
# ci_get_pic_bucket()
1973+
# ci_get_inventory_trigger_jobs()
1974+
# ci_get_ai_bucket()
1975+
# ci_get_ai_queue()
1976+
# ci_put_ai_queue()
1977+
# ci_create_noise_reduction_jobs()
1978+
# ci_create_stream_extract_jobs()
1979+
# ci_create_tts_jobs()
1980+
# ci_create_translation_jobs()
1981+
# ci_create_words_generalize_jobs()
1982+
ci_get_presigned_download_url()

0 commit comments

Comments
 (0)