MeUtils 2025.5.1.20.22.23__py3-none-any.whl → 2025.5.7.20.22.52__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {MeUtils-2025.5.1.20.22.23.dist-info → MeUtils-2025.5.7.20.22.52.dist-info}/METADATA +259 -259
- {MeUtils-2025.5.1.20.22.23.dist-info → MeUtils-2025.5.7.20.22.52.dist-info}/RECORD +21 -19
- examples/_openaisdk/openai_chatfire.py +2 -2
- meutils/ai_audio/tts/openai_tts.py +3 -1
- meutils/apis/fal/kling_videos.py +85 -0
- meutils/apis/fal/videos.py +4 -1
- meutils/apis/jimeng/common.py +20 -8
- meutils/apis/jimeng/files.py +18 -10
- meutils/apis/jimeng/images.py +6 -14
- meutils/apis/jimeng/videos.py +55 -198
- meutils/apis/jimeng/videos_videos.py +334 -0
- meutils/apis/oneapi/channel.py +43 -1
- meutils/apis/volcengine_apis/images.py +3 -0
- meutils/data/VERSION +1 -1
- meutils/llm/openai_polling/chat.py +1 -4
- meutils/schemas/oneapi/common.py +20 -7
- meutils/schemas/video_types.py +22 -3
- {MeUtils-2025.5.1.20.22.23.dist-info → MeUtils-2025.5.7.20.22.52.dist-info}/LICENSE +0 -0
- {MeUtils-2025.5.1.20.22.23.dist-info → MeUtils-2025.5.7.20.22.52.dist-info}/WHEEL +0 -0
- {MeUtils-2025.5.1.20.22.23.dist-info → MeUtils-2025.5.7.20.22.52.dist-info}/entry_points.txt +0 -0
- {MeUtils-2025.5.1.20.22.23.dist-info → MeUtils-2025.5.7.20.22.52.dist-info}/top_level.txt +0 -0
meutils/apis/jimeng/videos.py
CHANGED
@@ -19,7 +19,7 @@ from meutils.pipe import *
|
|
19
19
|
from meutils.str_utils.json_utils import json_path
|
20
20
|
|
21
21
|
from meutils.schemas.jimeng_types import BASE_URL, MODELS_MAP, FEISHU_URL
|
22
|
-
from meutils.schemas.video_types import
|
22
|
+
from meutils.schemas.video_types import VideoRequest
|
23
23
|
from meutils.schemas.task_types import TaskResponse
|
24
24
|
from meutils.apis.jimeng.common import get_headers, check_token
|
25
25
|
from meutils.apis.jimeng.files import upload_for_image, upload_for_video
|
@@ -31,45 +31,6 @@ from fake_useragent import UserAgent
|
|
31
31
|
ua = UserAgent()
|
32
32
|
|
33
33
|
|
34
|
-
async def create_realman_avatar(image_url: str, token: str):
|
35
|
-
if image_url.startswith("http"):
|
36
|
-
image_url = await upload_for_image(image_url, token)
|
37
|
-
|
38
|
-
url = "/mweb/v1/create_realman_avatar"
|
39
|
-
headers = get_headers(url, token)
|
40
|
-
|
41
|
-
payload = {
|
42
|
-
"input_list": [
|
43
|
-
{
|
44
|
-
"image_uri": image_url,
|
45
|
-
"submit_id": str(uuid.uuid4()),
|
46
|
-
"mode": 0
|
47
|
-
},
|
48
|
-
{
|
49
|
-
"image_uri": image_url,
|
50
|
-
"submit_id": str(uuid.uuid4()),
|
51
|
-
"mode": 1
|
52
|
-
}
|
53
|
-
]
|
54
|
-
}
|
55
|
-
|
56
|
-
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
57
|
-
response = await client.post(url, json=payload)
|
58
|
-
response.raise_for_status()
|
59
|
-
data = response.json()
|
60
|
-
logger.debug(bjson(data)) # 1914628189186
|
61
|
-
|
62
|
-
response = TaskResponse(metadata=data, system_fingerprint=token)
|
63
|
-
if task_ids := json_path(data, "$..task_id"): # 返回 imageurl vid
|
64
|
-
response.task_id = ' '.join(task_ids)
|
65
|
-
return response
|
66
|
-
|
67
|
-
else:
|
68
|
-
response.message = str(json_path(data, "$..message"))
|
69
|
-
response.status = "fail"
|
70
|
-
return response
|
71
|
-
|
72
|
-
|
73
34
|
async def get_task(task_id: str, token: str = "916fed81175f5186a2c05375699ea40d"):
|
74
35
|
"""
|
75
36
|
$..image_to_avatar 成功: 先检测图片or视频
|
@@ -88,26 +49,10 @@ async def get_task(task_id: str, token: str = "916fed81175f5186a2c05375699ea40d"
|
|
88
49
|
data = response.json()
|
89
50
|
logger.debug(bjson(data))
|
90
51
|
|
91
|
-
if json_path(data, "$..
|
92
|
-
resource_id_std = resource_id_loopy = ""
|
93
|
-
if resource_id_stds := json_path(data, "$..resource_id_std"):
|
94
|
-
resource_id_std = "".join(resource_id_stds)
|
95
|
-
|
96
|
-
if resource_id_loopys := json_path(data, "$..resource_id_loopy"):
|
97
|
-
resource_id_loopy = "".join(resource_id_loopys)
|
98
|
-
|
99
|
-
task_data = {
|
100
|
-
"resource_id_std": resource_id_std,
|
101
|
-
"resource_id_loopy": resource_id_loopy
|
102
|
-
}
|
103
|
-
response = TaskResponse(task_id=task_id, data=task_data, metadata=data)
|
104
|
-
if resource_id_std and resource_id_loopy:
|
105
|
-
response.status = "success"
|
106
|
-
|
107
|
-
if (message := json_path(data, "$..image_to_avatar.message")) and "fail" in str(message).lower():
|
108
|
-
response.message = str(message)
|
109
|
-
response.status = "fail"
|
52
|
+
if video_urls := json_path(data, "$..video_url"): # 角色检测 create_realman_avatar
|
110
53
|
|
54
|
+
task_data = dict(zip(["video"] * len(video_urls), video_urls))
|
55
|
+
response = TaskResponse(task_id=task_id, data=task_data, metadata=data, status="success")
|
111
56
|
return response
|
112
57
|
|
113
58
|
else:
|
@@ -122,137 +67,46 @@ async def get_task(task_id: str, token: str = "916fed81175f5186a2c05375699ea40d"
|
|
122
67
|
|
123
68
|
if video_urls := json_path(data, "$..[360p,480p,720p].video_url"):
|
124
69
|
response.data = [{"video": _} for _ in video_urls]
|
70
|
+
response.status = "success"
|
125
71
|
|
126
72
|
return response
|
127
73
|
|
128
74
|
|
129
|
-
async def create_task(request:
|
130
|
-
|
131
|
-
token = "7c5e148d9fa858e3180c42f843c20454" # 年付
|
132
|
-
token = "916fed81175f5186a2c05375699ea40d" # 月付
|
133
|
-
|
134
|
-
url = "/mweb/v1/batch_generate_video"
|
135
|
-
|
136
|
-
headers = get_headers(url, token)
|
137
|
-
|
138
|
-
model = request.model
|
139
|
-
scene = "lip_sync_image"
|
140
|
-
image_url = await upload_for_image(request.image_url, token)
|
141
|
-
|
142
|
-
# 角色检测
|
143
|
-
realman_avatar_response = await create_realman_avatar(image_url, token)
|
144
|
-
if realman_avatar_response.status == "fail":
|
145
|
-
return realman_avatar_response
|
146
|
-
|
147
|
-
else:
|
148
|
-
for _ in range(10):
|
149
|
-
task_response = await get_task(realman_avatar_response.task_id, token)
|
150
|
-
if task_response.status == "fail":
|
151
|
-
logger.debug("fail")
|
152
|
-
return task_response
|
153
|
-
elif task_response.status == "success":
|
154
|
-
logger.debug("success")
|
155
|
-
|
156
|
-
realman_avatar_response = task_response
|
157
|
-
break
|
158
|
-
else:
|
159
|
-
await asyncio.sleep(3)
|
160
|
-
continue
|
161
|
-
|
162
|
-
audio_vid, audio_url = await upload_for_video(request.audio_url, token)
|
163
|
-
|
164
|
-
resource_id_std = realman_avatar_response.data.get("resource_id_std")
|
165
|
-
resource_id_loopy = realman_avatar_response.data.get("resource_id_loopy")
|
75
|
+
async def create_task(request: VideoRequest, token: Optional[str] = None):
|
76
|
+
token = "d2d142fc877e696484cc2fc521127b36" ################### 线上注释掉
|
166
77
|
|
167
|
-
|
168
|
-
if request.video_url:
|
169
|
-
v2v_opt = {}
|
78
|
+
token = token or await get_next_token_for_polling(FEISHU_URL, check_token)
|
170
79
|
|
171
|
-
|
172
|
-
# "submit_id": "",
|
173
|
-
# "task_extra": "{\"promptSource\":\"photo_lip_sync\",\"generateTimes\":1,\"lipSyncInfo\":{\"sourceType\":\"local-file\",\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\"},\"isUseAiGenPrompt\":false,\"batchNumber\":1}",
|
174
|
-
# "http_common_info": {
|
175
|
-
# "aid": 513695
|
176
|
-
# },
|
177
|
-
# "input": {
|
178
|
-
# "seed": 3112889115,
|
179
|
-
# "video_gen_inputs": [
|
180
|
-
# {
|
181
|
-
# "v2v_opt": {},
|
182
|
-
# "i2v_opt": {
|
183
|
-
# "realman_avatar": {
|
184
|
-
# "enable": True,
|
185
|
-
# "origin_image": {
|
186
|
-
# # "width": 800,
|
187
|
-
# # "height": 1200,
|
188
|
-
# "image_uri": "tos-cn-i-tb4s082cfz/4dead1bfc8e84572a91f2e047016a351",
|
189
|
-
# "image_url": ""
|
190
|
-
# },
|
191
|
-
# "origin_audio": {
|
192
|
-
# # "duration": 9.976625,
|
193
|
-
# "vid": "v02870g10004cu8d4r7og65j2vr5opb0"
|
194
|
-
# },
|
195
|
-
#
|
196
|
-
# "resource_id_std": "381c534f-bcef-482e-8f17-5b30b64e41a1",
|
197
|
-
# "resource_id_loopy": "b9ac51cb-e26c-4b63-81d9-34ed24053032",
|
198
|
-
# #
|
199
|
-
# # "tts_info": "{\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\",\"source_type\":\"local-file\"}"
|
200
|
-
# }
|
201
|
-
# },
|
202
|
-
# "audio_vid": "v02870g10004cu8d4r7og65j2vr5opb0",
|
203
|
-
# "video_mode": 4
|
204
|
-
# }
|
205
|
-
# ]
|
206
|
-
# },
|
207
|
-
# "mode": "workbench",
|
208
|
-
# "history_option": {},
|
209
|
-
# "commerce_info": {
|
210
|
-
# "resource_id": "generate_video",
|
211
|
-
# "resource_id_type": "str",
|
212
|
-
# "resource_sub_type": "aigc",
|
213
|
-
# "benefit_type": "lip_sync_avatar_std", # 5积分
|
214
|
-
# # "benefit_type": "lip_sync_avatar_lively" # 10积分
|
215
|
-
# },
|
216
|
-
# "scene": "lip_sync_image",
|
217
|
-
# "client_trace_data": {},
|
218
|
-
# "submit_id_list": [
|
219
|
-
# str(uuid.uuid4())
|
220
|
-
# ]
|
221
|
-
# }
|
80
|
+
url = "/mweb/v1/generate_video"
|
222
81
|
|
223
|
-
|
224
|
-
i2v_opt = {
|
225
|
-
"realman_avatar": {
|
226
|
-
"enable": True,
|
227
|
-
"origin_image": {
|
228
|
-
"image_uri": image_url,
|
229
|
-
"image_url": ""
|
230
|
-
},
|
231
|
-
"resource_id_loopy": resource_id_loopy,
|
232
|
-
"resource_id_std": resource_id_std,
|
233
|
-
"origin_audio": {
|
234
|
-
"vid": audio_vid
|
235
|
-
},
|
236
|
-
# "tts_info": "{\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\",\"source_type\":\"local-file\"}"
|
237
|
-
}
|
238
|
-
}
|
82
|
+
headers = get_headers(url, token)
|
239
83
|
|
84
|
+
task_extra = {
|
85
|
+
"promptSource": "custom",
|
86
|
+
"originSubmitId": str(uuid.uuid4()),
|
87
|
+
"isDefaultSeed": 1,
|
88
|
+
"originTemplateId": "",
|
89
|
+
"imageNameMapping": {},
|
90
|
+
"isUseAiGenPrompt": False,
|
91
|
+
"batchNumber": 1
|
92
|
+
}
|
240
93
|
payload = {
|
241
|
-
"submit_id":
|
242
|
-
|
243
|
-
"http_common_info": {
|
244
|
-
"aid": 513695
|
245
|
-
},
|
94
|
+
"submit_id": str(uuid.uuid4()),
|
95
|
+
"task_extra": json.dumps(task_extra),
|
246
96
|
"input": {
|
247
|
-
"
|
97
|
+
"video_aspect_ratio": request.aspect_ratio,
|
98
|
+
"seed": 1751603315, ##### seed 10位
|
248
99
|
"video_gen_inputs": [
|
249
100
|
{
|
250
|
-
"
|
251
|
-
"
|
252
|
-
"
|
253
|
-
"video_mode":
|
101
|
+
"prompt": request.prompt,
|
102
|
+
"fps": 24,
|
103
|
+
"duration_ms": request.duration * 1000,
|
104
|
+
"video_mode": 2,
|
105
|
+
"template_id": ""
|
254
106
|
}
|
255
|
-
]
|
107
|
+
],
|
108
|
+
"priority": 0,
|
109
|
+
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0", # request.model
|
256
110
|
},
|
257
111
|
"mode": "workbench",
|
258
112
|
"history_option": {},
|
@@ -260,16 +114,23 @@ async def create_task(request: LipsyncVideoRquest, token: Optional[str] = None):
|
|
260
114
|
"resource_id": "generate_video",
|
261
115
|
"resource_id_type": "str",
|
262
116
|
"resource_sub_type": "aigc",
|
263
|
-
"benefit_type":
|
264
|
-
# "benefit_type": "lip_sync_avatar_lively" # 10积分
|
117
|
+
"benefit_type": "basic_video_operation_vgfm_v_three"
|
265
118
|
},
|
266
|
-
"
|
267
|
-
"client_trace_data": {},
|
268
|
-
"submit_id_list": [
|
269
|
-
str(uuid.uuid4())
|
270
|
-
]
|
119
|
+
"client_trace_data": {}
|
271
120
|
}
|
272
121
|
|
122
|
+
if request.image_url:
|
123
|
+
# image_url = "tos-cn-i-tb4s082cfz/a116c6a9dcbc41b889f9aabdef645456"
|
124
|
+
image_url = await upload_for_image(request.image_url, token, biz="video")
|
125
|
+
# vid, uri = await upload_for_video(request.image_url, token)
|
126
|
+
# logger.debug(f"vid: {vid}, uri: {uri}")
|
127
|
+
payload['input'].pop('video_aspect_ratio', None)
|
128
|
+
payload['input']['video_gen_inputs'][0]['first_frame_image'] = {
|
129
|
+
"width": 1024,
|
130
|
+
"height": 1024,
|
131
|
+
"image_uri": image_url
|
132
|
+
}
|
133
|
+
|
273
134
|
logger.debug(bjson(payload))
|
274
135
|
|
275
136
|
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
@@ -284,22 +145,18 @@ async def create_task(request: LipsyncVideoRquest, token: Optional[str] = None):
|
|
284
145
|
|
285
146
|
|
286
147
|
if __name__ == '__main__':
|
287
|
-
token =
|
148
|
+
token = None
|
149
|
+
token = "d2d142fc877e696484cc2fc521127b36"
|
288
150
|
|
289
|
-
request =
|
290
|
-
model="
|
291
|
-
|
292
|
-
|
293
|
-
audio_url="https://oss.ffire.cc/files/lipsync.mp3"
|
151
|
+
request = VideoRequest(
|
152
|
+
model="dreamina_ic_generate_video_model_vgfm_3.0",
|
153
|
+
prompt="笑起来",
|
154
|
+
image_url="https://oss.ffire.cc/files/kling_watermark.png", # 图生有问题
|
294
155
|
)
|
295
156
|
|
296
|
-
# with timer():
|
297
|
-
# r = arun(create_realman_avatar(request.image_url, token))
|
298
|
-
# arun(get_task(r.task_id))
|
299
|
-
|
300
|
-
# image_uri = "tos-cn-i-tb4s082cfz/387649a361e546f89549bd3510ab926d"
|
301
|
-
# task_ids = arun(create_realman_avatar(image_uri, token="7c5e148d9fa858e3180c42f843c20454"))
|
302
|
-
# arun(mget_generate_task(task_ids))
|
303
157
|
with timer():
|
304
|
-
r = arun(create_task(request))
|
158
|
+
r = arun(create_task(request, token))
|
159
|
+
print(r)
|
160
|
+
|
305
161
|
# arun(get_task(r.task_id))
|
162
|
+
# arun(get_task(r.task_id, "d2d142fc877e696484cc2fc521127b36"))
|
@@ -0,0 +1,334 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Project : AI. @by PyCharm
|
4
|
+
# @File : lip_sync
|
5
|
+
# @Time : 2025/1/3 16:17
|
6
|
+
# @Author : betterme
|
7
|
+
# @WeChat : meutils
|
8
|
+
# @Software : PyCharm
|
9
|
+
# @Description :
|
10
|
+
"""
|
11
|
+
1. 上传图片 image_to_avatar检测
|
12
|
+
2. 上传视频 video_to_avatar检测
|
13
|
+
3. 上传音频+创建任务
|
14
|
+
|
15
|
+
"""
|
16
|
+
import asyncio
|
17
|
+
|
18
|
+
from meutils.pipe import *
|
19
|
+
from meutils.str_utils.json_utils import json_path
|
20
|
+
|
21
|
+
from meutils.schemas.jimeng_types import BASE_URL, MODELS_MAP, FEISHU_URL
|
22
|
+
from meutils.schemas.video_types import LipsyncVideoRequest
|
23
|
+
from meutils.schemas.task_types import TaskResponse
|
24
|
+
from meutils.apis.jimeng.common import get_headers, check_token
|
25
|
+
from meutils.apis.jimeng.files import upload_for_image, upload_for_video
|
26
|
+
|
27
|
+
from meutils.config_utils.lark_utils import get_next_token_for_polling
|
28
|
+
|
29
|
+
from fake_useragent import UserAgent
|
30
|
+
|
31
|
+
ua = UserAgent()
|
32
|
+
|
33
|
+
|
34
|
+
async def create_realman_avatar(image_url: str, token: str):
|
35
|
+
if image_url.startswith("http"):
|
36
|
+
image_url = await upload_for_image(image_url, token)
|
37
|
+
|
38
|
+
url = "/mweb/v1/create_realman_avatar"
|
39
|
+
headers = get_headers(url, token)
|
40
|
+
|
41
|
+
payload = {
|
42
|
+
"input_list": [
|
43
|
+
{
|
44
|
+
"image_uri": image_url,
|
45
|
+
"submit_id": str(uuid.uuid4()),
|
46
|
+
"mode": 0
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"image_uri": image_url,
|
50
|
+
"submit_id": str(uuid.uuid4()),
|
51
|
+
"mode": 1
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
|
56
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
57
|
+
response = await client.post(url, json=payload)
|
58
|
+
response.raise_for_status()
|
59
|
+
data = response.json()
|
60
|
+
logger.debug(bjson(data)) # 1914628189186
|
61
|
+
|
62
|
+
response = TaskResponse(metadata=data, system_fingerprint=token)
|
63
|
+
if task_ids := json_path(data, "$..task_id"): # 返回 imageurl vid
|
64
|
+
response.task_id = ' '.join(task_ids)
|
65
|
+
return response
|
66
|
+
|
67
|
+
else:
|
68
|
+
response.message = str(json_path(data, "$..message"))
|
69
|
+
response.status = "fail"
|
70
|
+
return response
|
71
|
+
|
72
|
+
|
73
|
+
async def get_task(task_id: str, token: str = "916fed81175f5186a2c05375699ea40d"):
|
74
|
+
"""
|
75
|
+
$..image_to_avatar 成功: 先检测图片or视频
|
76
|
+
:param task_ids:
|
77
|
+
:return:
|
78
|
+
"""
|
79
|
+
task_ids = task_id.split()
|
80
|
+
|
81
|
+
url = "/mweb/v1/mget_generate_task"
|
82
|
+
headers = get_headers(url, token)
|
83
|
+
|
84
|
+
payload = {"task_id_list": task_ids}
|
85
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
86
|
+
response = await client.post(url, json=payload)
|
87
|
+
response.raise_for_status()
|
88
|
+
data = response.json()
|
89
|
+
logger.debug(bjson(data))
|
90
|
+
|
91
|
+
if json_path(data, "$..image_to_avatar"): # 角色检测 create_realman_avatar
|
92
|
+
resource_id_std = resource_id_loopy = ""
|
93
|
+
if resource_id_stds := json_path(data, "$..resource_id_std"):
|
94
|
+
resource_id_std = "".join(resource_id_stds)
|
95
|
+
|
96
|
+
if resource_id_loopys := json_path(data, "$..resource_id_loopy"):
|
97
|
+
resource_id_loopy = "".join(resource_id_loopys)
|
98
|
+
|
99
|
+
task_data = {
|
100
|
+
"resource_id_std": resource_id_std,
|
101
|
+
"resource_id_loopy": resource_id_loopy
|
102
|
+
}
|
103
|
+
response = TaskResponse(task_id=task_id, data=task_data, metadata=data)
|
104
|
+
if resource_id_std and resource_id_loopy:
|
105
|
+
response.status = "success"
|
106
|
+
|
107
|
+
if (message := json_path(data, "$..image_to_avatar.message")) and "fail" in str(message).lower():
|
108
|
+
response.message = str(message)
|
109
|
+
response.status = "fail"
|
110
|
+
|
111
|
+
return response
|
112
|
+
|
113
|
+
else:
|
114
|
+
response = TaskResponse(task_id=task_id, metadata=data)
|
115
|
+
if (message := json_path(data, "$..fail_msg")) and "success" not in str(message).lower():
|
116
|
+
response.message = str(message)
|
117
|
+
response.status = "fail"
|
118
|
+
return response
|
119
|
+
|
120
|
+
if will_cost := json_path(data, "$..will_cost"):
|
121
|
+
response.will_cost = will_cost[0]
|
122
|
+
|
123
|
+
if video_urls := json_path(data, "$..[360p,480p,720p].video_url"):
|
124
|
+
response.data = [{"video": _} for _ in video_urls]
|
125
|
+
|
126
|
+
return response
|
127
|
+
|
128
|
+
|
129
|
+
async def create_task(request: LipsyncVideoRequest, token: Optional[str] = None):
|
130
|
+
# token = token or await get_next_token_for_polling(FEISHU_URL, check_token)
|
131
|
+
token = "7c5e148d9fa858e3180c42f843c20454" # 年付
|
132
|
+
token = "916fed81175f5186a2c05375699ea40d" # 月付
|
133
|
+
|
134
|
+
url = "/mweb/v1/batch_generate_video"
|
135
|
+
|
136
|
+
headers = get_headers(url, token)
|
137
|
+
|
138
|
+
model = request.model
|
139
|
+
scene = "lip_sync_image"
|
140
|
+
image_url = await upload_for_image(request.image_url, token)
|
141
|
+
|
142
|
+
# 角色检测
|
143
|
+
realman_avatar_response = await create_realman_avatar(image_url, token)
|
144
|
+
if realman_avatar_response.status == "fail":
|
145
|
+
return realman_avatar_response
|
146
|
+
|
147
|
+
else:
|
148
|
+
for _ in range(10):
|
149
|
+
task_response = await get_task(realman_avatar_response.task_id, token)
|
150
|
+
if task_response.status == "fail":
|
151
|
+
logger.debug("fail")
|
152
|
+
return task_response
|
153
|
+
elif task_response.status == "success":
|
154
|
+
logger.debug("success")
|
155
|
+
|
156
|
+
realman_avatar_response = task_response
|
157
|
+
break
|
158
|
+
else:
|
159
|
+
await asyncio.sleep(3)
|
160
|
+
continue
|
161
|
+
|
162
|
+
audio_vid, audio_url = await upload_for_video(request.audio_url, token)
|
163
|
+
|
164
|
+
resource_id_std = realman_avatar_response.data.get("resource_id_std")
|
165
|
+
resource_id_loopy = realman_avatar_response.data.get("resource_id_loopy")
|
166
|
+
|
167
|
+
i2v_opt = v2v_opt = {}
|
168
|
+
if request.video_url:
|
169
|
+
v2v_opt = {}
|
170
|
+
|
171
|
+
# payload = {
|
172
|
+
# "submit_id": "",
|
173
|
+
# "task_extra": "{\"promptSource\":\"photo_lip_sync\",\"generateTimes\":1,\"lipSyncInfo\":{\"sourceType\":\"local-file\",\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\"},\"isUseAiGenPrompt\":false,\"batchNumber\":1}",
|
174
|
+
# "http_common_info": {
|
175
|
+
# "aid": 513695
|
176
|
+
# },
|
177
|
+
# "input": {
|
178
|
+
# "seed": 3112889115,
|
179
|
+
# "video_gen_inputs": [
|
180
|
+
# {
|
181
|
+
# "v2v_opt": {},
|
182
|
+
# "i2v_opt": {
|
183
|
+
# "realman_avatar": {
|
184
|
+
# "enable": True,
|
185
|
+
# "origin_image": {
|
186
|
+
# # "width": 800,
|
187
|
+
# # "height": 1200,
|
188
|
+
# "image_uri": "tos-cn-i-tb4s082cfz/4dead1bfc8e84572a91f2e047016a351",
|
189
|
+
# "image_url": ""
|
190
|
+
# },
|
191
|
+
# "origin_audio": {
|
192
|
+
# # "duration": 9.976625,
|
193
|
+
# "vid": "v02870g10004cu8d4r7og65j2vr5opb0"
|
194
|
+
# },
|
195
|
+
#
|
196
|
+
# "resource_id_std": "381c534f-bcef-482e-8f17-5b30b64e41a1",
|
197
|
+
# "resource_id_loopy": "b9ac51cb-e26c-4b63-81d9-34ed24053032",
|
198
|
+
# #
|
199
|
+
# # "tts_info": "{\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\",\"source_type\":\"local-file\"}"
|
200
|
+
# }
|
201
|
+
# },
|
202
|
+
# "audio_vid": "v02870g10004cu8d4r7og65j2vr5opb0",
|
203
|
+
# "video_mode": 4
|
204
|
+
# }
|
205
|
+
# ]
|
206
|
+
# },
|
207
|
+
# "mode": "workbench",
|
208
|
+
# "history_option": {},
|
209
|
+
# "commerce_info": {
|
210
|
+
# "resource_id": "generate_video",
|
211
|
+
# "resource_id_type": "str",
|
212
|
+
# "resource_sub_type": "aigc",
|
213
|
+
# "benefit_type": "lip_sync_avatar_std", # 5积分
|
214
|
+
# # "benefit_type": "lip_sync_avatar_lively" # 10积分
|
215
|
+
# },
|
216
|
+
# "scene": "lip_sync_image",
|
217
|
+
# "client_trace_data": {},
|
218
|
+
# "submit_id_list": [
|
219
|
+
# str(uuid.uuid4())
|
220
|
+
# ]
|
221
|
+
# }
|
222
|
+
|
223
|
+
if request.image_url:
|
224
|
+
i2v_opt = {
|
225
|
+
"realman_avatar": {
|
226
|
+
"enable": True,
|
227
|
+
"origin_image": {
|
228
|
+
"image_uri": image_url,
|
229
|
+
"image_url": ""
|
230
|
+
},
|
231
|
+
"resource_id_loopy": resource_id_loopy,
|
232
|
+
"resource_id_std": resource_id_std,
|
233
|
+
"origin_audio": {
|
234
|
+
"vid": audio_vid
|
235
|
+
},
|
236
|
+
# "tts_info": "{\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\",\"source_type\":\"local-file\"}"
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
payload = {
|
241
|
+
"submit_id": "",
|
242
|
+
# "task_extra": "{\"promptSource\":\"photo_lip_sync\",\"generateTimes\":1,\"lipSyncInfo\":{\"sourceType\":\"local-file\",\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\"},\"isUseAiGenPrompt\":false,\"batchNumber\":1}",
|
243
|
+
"http_common_info": {
|
244
|
+
"aid": 513695
|
245
|
+
},
|
246
|
+
"input": {
|
247
|
+
"seed": 2032846910,
|
248
|
+
"video_gen_inputs": [
|
249
|
+
{
|
250
|
+
"v2v_opt": v2v_opt,
|
251
|
+
"i2v_opt": i2v_opt,
|
252
|
+
"audio_vid": audio_vid,
|
253
|
+
"video_mode": 4
|
254
|
+
}
|
255
|
+
]
|
256
|
+
},
|
257
|
+
"mode": "workbench",
|
258
|
+
"history_option": {},
|
259
|
+
"commerce_info": {
|
260
|
+
"resource_id": "generate_video",
|
261
|
+
"resource_id_type": "str",
|
262
|
+
"resource_sub_type": "aigc",
|
263
|
+
"benefit_type": model,
|
264
|
+
# "benefit_type": "lip_sync_avatar_lively" # 10积分
|
265
|
+
},
|
266
|
+
"scene": scene,
|
267
|
+
"client_trace_data": {},
|
268
|
+
"submit_id_list": [
|
269
|
+
str(uuid.uuid4())
|
270
|
+
]
|
271
|
+
}
|
272
|
+
|
273
|
+
logger.debug(bjson(payload))
|
274
|
+
|
275
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
276
|
+
response = await client.post(url, json=payload)
|
277
|
+
response.raise_for_status()
|
278
|
+
data = response.json()
|
279
|
+
logger.debug(bjson(data))
|
280
|
+
|
281
|
+
if task_ids := json_path(data, "$..task.task_id"):
|
282
|
+
task_id = task_ids[0]
|
283
|
+
return TaskResponse(task_id=task_id, system_fingerprint=token)
|
284
|
+
|
285
|
+
|
286
|
+
# {
|
287
|
+
# "submit_id": "740e28e3-12fd-4ab6-82da-7f2028ac6314",
|
288
|
+
# "task_extra": "{\"promptSource\":\"custom\",\"originSubmitId\":\"3575ebec-1d35-42f1-bd19-6cf0c8dee0b1\",\"isDefaultSeed\":1,\"originTemplateId\":\"\",\"imageNameMapping\":{},\"isUseAiGenPrompt\":false,\"batchNumber\":1}",
|
289
|
+
# "input": {
|
290
|
+
# "video_aspect_ratio": "16:9",
|
291
|
+
# "seed": 840565633,
|
292
|
+
# "video_gen_inputs": [
|
293
|
+
# {
|
294
|
+
# "prompt": "现代几何构图海报模板,庆祝男演员都市爱情剧《街角晚风》成功。画面分割为几个深红和灰色块面。一个灰色块内展示清晰的德塔文景气指数上升曲线图(深红线条)。一个色块放置男演员侧脸剧照。剧名和标语“人气飙升,全城热恋”分布在不同色块上,字体设计现代。整体风格简约、结构化、高级。",
|
295
|
+
# "fps": 24,
|
296
|
+
# "duration_ms": 5000,
|
297
|
+
# "video_mode": 2,
|
298
|
+
# "template_id": ""
|
299
|
+
# }
|
300
|
+
# ],
|
301
|
+
# "priority": 0,
|
302
|
+
# "model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0"
|
303
|
+
# },
|
304
|
+
# "mode": "workbench",
|
305
|
+
# "history_option": {},
|
306
|
+
# "commerce_info": {
|
307
|
+
# "resource_id": "generate_video",
|
308
|
+
# "resource_id_type": "str",
|
309
|
+
# "resource_sub_type": "aigc",
|
310
|
+
# "benefit_type": "basic_video_operation_vgfm_v_three"
|
311
|
+
# },
|
312
|
+
# "client_trace_data": {}
|
313
|
+
# # }
|
314
|
+
|
315
|
+
if __name__ == '__main__':
|
316
|
+
token = "916fed81175f5186a2c05375699ea40d"
|
317
|
+
|
318
|
+
request = LipsyncVideoRequest(
|
319
|
+
model="lip_sync_avatar_std",
|
320
|
+
image_url="https://oss.ffire.cc/files/kling_watermark.png",
|
321
|
+
video_url="",
|
322
|
+
audio_url="https://oss.ffire.cc/files/lipsync.mp3"
|
323
|
+
)
|
324
|
+
|
325
|
+
# with timer():
|
326
|
+
# r = arun(create_realman_avatar(request.image_url, token))
|
327
|
+
# arun(get_task(r.task_id))
|
328
|
+
|
329
|
+
# image_uri = "tos-cn-i-tb4s082cfz/387649a361e546f89549bd3510ab926d"
|
330
|
+
# task_ids = arun(create_realman_avatar(image_uri, token="7c5e148d9fa858e3180c42f843c20454"))
|
331
|
+
# arun(mget_generate_task(task_ids))
|
332
|
+
with timer():
|
333
|
+
r = arun(create_task(request))
|
334
|
+
# arun(get_task(r.task_id))
|