MeUtils 2025.1.17.19.49.29__py3-none-any.whl → 2025.1.23.10.16.28__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.1.17.19.49.29.dist-info → MeUtils-2025.1.23.10.16.28.dist-info}/METADATA +27 -27
- {MeUtils-2025.1.17.19.49.29.dist-info → MeUtils-2025.1.23.10.16.28.dist-info}/RECORD +31 -30
- examples/_openaisdk/openai_chatfire.py +4 -2
- examples/_openaisdk/openai_deepseek.py +7 -6
- examples/_openaisdk/openai_doubao.py +16 -7
- examples/_openaisdk/openai_embeddings.py +1 -1
- meutils/apis/jimeng/lip_sync.py → examples/_openaisdk/openai_x.py +3 -2
- examples/bserver.py +60 -518
- meutils/apis/fal/videos.py +13 -7
- meutils/apis/hailuoai/videos.py +16 -6
- meutils/apis/images/edits.py +4 -4
- meutils/apis/images/recraft.py +5 -5
- meutils/apis/jimeng/common.py +4 -5
- meutils/apis/jimeng/doubao.py +2 -2
- meutils/apis/jimeng/files.py +63 -21
- meutils/apis/jimeng/images.py +29 -10
- meutils/apis/jimeng/videos.py +236 -0
- meutils/apis/oneapi/user.py +3 -1
- meutils/data/VERSION +1 -1
- meutils/io/files_utils.py +9 -3
- meutils/llm/completions/agents/file.py +7 -4
- meutils/schemas/hailuo_types.py +8 -2
- meutils/schemas/image_types.py +9 -4
- meutils/schemas/oneapi/common.py +136 -41
- meutils/schemas/task_types.py +2 -0
- meutils/schemas/video_types.py +11 -1
- meutils/str_utils/json_utils.py +29 -1
- {MeUtils-2025.1.17.19.49.29.dist-info → MeUtils-2025.1.23.10.16.28.dist-info}/LICENSE +0 -0
- {MeUtils-2025.1.17.19.49.29.dist-info → MeUtils-2025.1.23.10.16.28.dist-info}/WHEEL +0 -0
- {MeUtils-2025.1.17.19.49.29.dist-info → MeUtils-2025.1.23.10.16.28.dist-info}/entry_points.txt +0 -0
- {MeUtils-2025.1.17.19.49.29.dist-info → MeUtils-2025.1.23.10.16.28.dist-info}/top_level.txt +0 -0
meutils/apis/fal/videos.py
CHANGED
@@ -50,13 +50,16 @@ async def get_task(task_id: str, token: Optional[str] = None):
|
|
50
50
|
application = f"fal-ai/{model}"
|
51
51
|
|
52
52
|
client = AsyncClient(key=token)
|
53
|
-
|
53
|
+
response = await client.status(application, request_id, with_logs=False)
|
54
|
+
logger.debug(response)
|
54
55
|
|
55
|
-
response = await client.result(application, request_id)
|
56
|
-
# AsyncRequestHandle(request_id='0b7ab6b8-c7dc-4f17-a655-4ee56dd0f864')
|
56
|
+
# response = await client.result(application, request_id)
|
57
|
+
# client.AsyncRequestHandle(request_id='0b7ab6b8-c7dc-4f17-a655-4ee56dd0f864')
|
57
58
|
return response
|
58
59
|
|
59
60
|
|
61
|
+
|
62
|
+
|
60
63
|
if __name__ == '__main__':
|
61
64
|
model = "latentsync"
|
62
65
|
model = "sync-lipsync"
|
@@ -70,8 +73,11 @@ if __name__ == '__main__':
|
|
70
73
|
|
71
74
|
r = arun(create_task(request))
|
72
75
|
|
73
|
-
token = "3f712efa-a692-4e7f-9409-e6c505bab4e2:151a0b6093312cc8f66fc52b7c4c92a8"
|
74
|
-
model = "0b7ab6b8-c7dc-4f17-a655-4ee56dd0f864"
|
75
76
|
|
76
|
-
|
77
|
-
|
77
|
+
task_id = r.task_id
|
78
|
+
arun(get_task(task_id, r.system_fingerprint))
|
79
|
+
|
80
|
+
# task_id="latentsync::d4133f01-0f5b-4213-abe4-d14abdb57e3f"
|
81
|
+
# token = "3f712efa-a692-4e7f-9409-e6c505bab4e2:151a0b6093312cc8f66fc52b7c4c92a8"
|
82
|
+
|
83
|
+
# r = arun(get_task(task_id, token))
|
meutils/apis/hailuoai/videos.py
CHANGED
@@ -35,14 +35,19 @@ send_message = partial(
|
|
35
35
|
)
|
36
36
|
|
37
37
|
MODEL_MAPPING = {
|
38
|
-
# video-01
|
39
|
-
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
38
|
+
# video-01 video-01 video-01-live2d S2V-01
|
39
|
+
|
40
|
+
"t2v-01": "23000",
|
41
|
+
"i2v-01": "23001",
|
42
|
+
"i2v-01-live": "23011",
|
43
|
+
"video-01-live2d": "23011",
|
44
|
+
"s2v-01": "23021",
|
43
45
|
}
|
44
46
|
|
45
47
|
|
48
|
+
# minimax_video-01,minimax_video-01-live2d,,minimax_t2v-01,minimax_i2v-01,minimax_i2v-01-live,minimax_s2v-01
|
49
|
+
|
50
|
+
|
46
51
|
async def upload(file: bytes, token: Optional[str] = None, vip: Optional[bool] = True):
|
47
52
|
global BASE_URL, FEISHU_URL
|
48
53
|
if vip:
|
@@ -217,6 +222,11 @@ async def create_task(request: VideoRequest, token: Optional[str] = None, vip: O
|
|
217
222
|
# "type": "png",
|
218
223
|
"url": request.first_frame_image,
|
219
224
|
}
|
225
|
+
|
226
|
+
# {"desc": "跳起来", "useOriginPrompt": false, "fileList": [{"id": "338311163211288581",
|
227
|
+
# "url": "https://cdn.hailuoai.video/moss/prod/2025-01-22-11/user/multi_chat_file/de5a4cec-eb26-4380-94e4-13b268bf5c0d.jpg",
|
228
|
+
# "name": "duikoux.jpg", "type": "jpg"}],
|
229
|
+
# "modelID": "23021", "quantity": "1"}
|
220
230
|
else:
|
221
231
|
data = await upload(file, token=refresh_token, vip=vip)
|
222
232
|
file_data = {
|
@@ -227,7 +237,7 @@ async def create_task(request: VideoRequest, token: Optional[str] = None, vip: O
|
|
227
237
|
}
|
228
238
|
|
229
239
|
payload["fileList"].append(file_data)
|
230
|
-
payload["modelID"] = MODEL_MAPPING.get(request.model, "23001")
|
240
|
+
payload["modelID"] = MODEL_MAPPING.get(request.model.lower(), "23001")
|
231
241
|
|
232
242
|
logger.debug(bjson(payload))
|
233
243
|
|
meutils/apis/images/edits.py
CHANGED
@@ -102,18 +102,18 @@ async def edit_image(request: ImageProcess):
|
|
102
102
|
}
|
103
103
|
|
104
104
|
if request.model == "remove-watermark":
|
105
|
-
if mask:
|
105
|
+
if mask: ####### todo: mask 抠图
|
106
106
|
payload['type'] = "2"
|
107
|
-
return await make_request_for_baidu(payload)
|
107
|
+
return await make_request_for_baidu(payload, response_format=request.response_format)
|
108
108
|
|
109
109
|
elif request.model == "clarity":
|
110
110
|
payload['type'] = "3"
|
111
|
-
return await make_request_for_baidu(payload)
|
111
|
+
return await make_request_for_baidu(payload, response_format=request.response_format)
|
112
112
|
|
113
113
|
elif request.model == "expand":
|
114
114
|
payload['type'] = "4"
|
115
115
|
payload['ext_ratio'] = request.aspect_ratio
|
116
|
-
return await make_request_for_baidu(payload)
|
116
|
+
return await make_request_for_baidu(payload, response_format=request.response_format)
|
117
117
|
################################################################################################
|
118
118
|
|
119
119
|
elif request.model == "rmbg-2.0":
|
meutils/apis/images/recraft.py
CHANGED
@@ -143,10 +143,10 @@ if __name__ == '__main__':
|
|
143
143
|
**data
|
144
144
|
)
|
145
145
|
|
146
|
-
with timer():
|
147
|
-
|
146
|
+
# with timer():
|
147
|
+
# arun(generate(request, token=token))
|
148
148
|
# tokens = [token]
|
149
149
|
|
150
|
-
|
151
|
-
|
152
|
-
|
150
|
+
tokens = list(arun(aget_spreadsheet_values(feishu_url=FEISHU_URL, to_dataframe=True))[0]) | xfilter_
|
151
|
+
|
152
|
+
r = arun(check_token(tokens))
|
meutils/apis/jimeng/common.py
CHANGED
@@ -16,8 +16,7 @@ from meutils.schemas.openai_types import TTSRequest
|
|
16
16
|
|
17
17
|
from meutils.schemas.jimeng_types import BASE_URL, MODELS_MAP
|
18
18
|
from meutils.str_utils.regular_expression import parse_url
|
19
|
-
from meutils.apis.jimeng.files import
|
20
|
-
from meutils.io.files_utils import to_bytes
|
19
|
+
from meutils.apis.jimeng.files import upload_for_image
|
21
20
|
from meutils.caches.redis_cache import cache
|
22
21
|
|
23
22
|
from fake_useragent import UserAgent
|
@@ -25,7 +24,7 @@ from fake_useragent import UserAgent
|
|
25
24
|
ua = UserAgent()
|
26
25
|
|
27
26
|
|
28
|
-
def get_headers(url, token="693701c43e477b7c405cc7e2fef0ddbd"):
|
27
|
+
def get_headers(url, token: str = "693701c43e477b7c405cc7e2fef0ddbd"):
|
29
28
|
device_time = f"{int(time.time())}"
|
30
29
|
sign = md5(
|
31
30
|
# f"9e2c|receive|7|5.8.0|{device_time}||11ac"
|
@@ -112,8 +111,7 @@ async def create_draft_content(request: ImageRequest, token: str):
|
|
112
111
|
|
113
112
|
if urls := parse_url(request.prompt):
|
114
113
|
url = urls[-1]
|
115
|
-
|
116
|
-
image_uri = upload(await to_bytes(url), upload_token)
|
114
|
+
image_uri = upload_for_image(url, token)
|
117
115
|
|
118
116
|
request.prompt = request.prompt.replace(url, '')
|
119
117
|
request.model = "high_aes_general_v20_L:general_v2.0_L" # 2.1不支持图片编辑
|
@@ -319,6 +317,7 @@ if __name__ == '__main__':
|
|
319
317
|
token = "dcf7bbc31faed9740b0bf748cd4d2c74"
|
320
318
|
token = "38d7d300b5e0a803431ef88d8d2acfef"
|
321
319
|
token = "916fed81175f5186a2c05375699ea40d"
|
320
|
+
token = "7c5e148d9fa858e3180c42f843c20454"
|
322
321
|
# arun(get_credit(token))
|
323
322
|
arun(check_token(token))
|
324
323
|
|
meutils/apis/jimeng/doubao.py
CHANGED
@@ -13,13 +13,13 @@ from meutils.pipe import *
|
|
13
13
|
from meutils.apis.jimeng.doubao_utils import generate_cookie
|
14
14
|
|
15
15
|
from meutils.schemas.image_types import ImageRequest
|
16
|
-
|
16
|
+
|
17
17
|
from meutils.schemas.jimeng_types import BASE_URL, MODELS_MAP, FEISHU_URL
|
18
18
|
from meutils.apis.jimeng.common import create_draft_content, get_headers, check_token
|
19
19
|
from meutils.config_utils.lark_utils import get_next_token_for_polling
|
20
20
|
|
21
21
|
|
22
|
-
async def
|
22
|
+
async def create_():
|
23
23
|
headers = {
|
24
24
|
'agw-js-conv': 'str',
|
25
25
|
'Cookie': 's_v_web_id=verify_m4t9wrdc_qgbhUw0z_07iP_4GFV_8HA7_6jr0e9lLCqQO; passport_csrf_token=8a8aa82fa109ecb3cb25e7afa10de214; passport_csrf_token_default=8a8aa82fa109ecb3cb25e7afa10de214; oauth_token=e45378cb-5afd-4495-88f5-58440e321b48; n_mh=lG4jjJNpPRqpnflIMXQoPMflNZdP31M8fFqgdR9Id5g; uid_tt=1a11a8af13cf1c878482fa862287107c; uid_tt_ss=1a11a8af13cf1c878482fa862287107c; sid_tt=de2215a7bb8e442774cf388f03fac84c; sessionid=de2215a7bb8e442774cf388f03fac84c; sessionid_ss=de2215a7bb8e442774cf388f03fac84c; is_staff_user=false; store-region=cn-js; store-region-src=uid; odin_tt=774fcc6d25d5259fd2af19858e0518c64943eb788718658b403ad8eb13ebbc6ebcb4c42620e87a48b2efb45fe78dc163b82399750898bb201c89f324b9e25b94; passport_auth_status=042935fbff60617ac0735d3ba4cfb559%2C7c535e1ccd98b367728b6560feb66a2e; passport_auth_status_ss=042935fbff60617ac0735d3ba4cfb559%2C7c535e1ccd98b367728b6560feb66a2e; sid_guard=de2215a7bb8e442774cf388f03fac84c%7C1734489199%7C5184000%7CSun%2C+16-Feb-2025+02%3A33%3A19+GMT; sid_ucp_v1=1.0.0-KGQyN2NlYjIxNTA1NTc3ZjI3NWQ2MjZkY2FhNGM3MGM0NzdkNGVjZDMKHwjAreC708zWBBDv6Ii7BhjCsR4gDDDn782qBjgIQCYaAmxxIiBkZTIyMTVhN2JiOGU0NDI3NzRjZjM4OGYwM2ZhYzg0Yw; ssid_ucp_v1=1.0.0-KGQyN2NlYjIxNTA1NTc3ZjI3NWQ2MjZkY2FhNGM3MGM0NzdkNGVjZDMKHwjAreC708zWBBDv6Ii7BhjCsR4gDDDn782qBjgIQCYaAmxxIiBkZTIyMTVhN2JiOGU0NDI3NzRjZjM4OGYwM2ZhYzg0Yw; ttwid=1%7C4rAQ216JOophOdIJRX4cHa6E8FSBjbjqHCKmFCNrQuc%7C1734510550%7C6217dce55189d102c393a4de7022e9ee2e2fa75f211108551b349a0a04532921; passport_fe_beating_status=true; tt_scid=b.csKGNI6QALEo8gG9vJu3nCfptGnLkTxVXPX.wNPQ0q9PaXuKzXfuFQC0i2U7gVa974; gd_random_1831913=eyJtYXRjaCI6ZmFsc2UsInBlcmNlbnQiOjAuMjIzMzcxMDAwNzk1MzUxNzd9.NuOx3z2e4BUOJrwTMG9F3lxrnhmz9jNR6BrhQYU4BhI; gd_random_1525008=eyJtYXRjaCI6ZmFsc2UsInBlcmNlbnQiOjAuMjIzMzcxMDAwNzk1MzUxNzd9.NuOx3z2e4BUOJrwTMG9F3lxrnhmz9jNR6BrhQYU4BhI; gd_random_1831904=eyJtYXRjaCI6ZmFsc2UsInBlcmNlbnQiOjAuMjIzMzcxMDAwNzk1MzUxNzd9.NuOx3z2e4BUOJrwTMG9F3lxrnhmz9jNR6BrhQYU4BhI; msToken=enism5q1i_XLtL8VKKjkjidcvGhyW0U3EGJBI19P3fyqk8NsW4fXW4g8s4TnlgRaF-aWS0kHrmNnENw5L4mFRyyz6A5yZbpR3nCRYJrvBi3-GrtptyOBhznILSv4OO0',
|
meutils/apis/jimeng/files.py
CHANGED
@@ -14,6 +14,7 @@ import hashlib
|
|
14
14
|
|
15
15
|
from meutils.pipe import *
|
16
16
|
from meutils.caches.redis_cache import cache
|
17
|
+
from meutils.io.files_utils import to_bytes
|
17
18
|
|
18
19
|
|
19
20
|
def random_str(n):
|
@@ -99,7 +100,7 @@ class JJRequest:
|
|
99
100
|
|
100
101
|
|
101
102
|
@cache(ttl=15 * 60)
|
102
|
-
def upload(image: bytes, upload_token: dict): # oss 跨账号不知道是否可以使用
|
103
|
+
async def upload(image: bytes, upload_token: dict): # oss 跨账号不知道是否可以使用
|
103
104
|
# e = auth = upload_token['data']['auth'] # 豆包
|
104
105
|
data = upload_token['data']
|
105
106
|
service_id = data.get('service_id', '3jr8j4ixpe') # 即梦 3jr8j4ixpe 豆包 a9rns2rl98
|
@@ -164,17 +165,21 @@ def upload(image: bytes, upload_token: dict): # oss 跨账号不知道是否可
|
|
164
165
|
# upload_url = f"https://tos-hl-x.snssdk.com/upload/v1/{oss_uri}"
|
165
166
|
upload_url = f"https://{response['Result']['UploadAddress']['UploadHosts'][0]}/upload/v1/{oss_uri}"
|
166
167
|
|
167
|
-
response = requests.post(upload_url, headers=headers, data=image)
|
168
|
-
response.raise_for_status()
|
169
|
-
response = response.json()
|
168
|
+
# response = requests.post(upload_url, headers=headers, data=image)
|
169
|
+
# response.raise_for_status()
|
170
|
+
# response = response.json()
|
171
|
+
# logger.debug(response)
|
170
172
|
|
171
|
-
|
173
|
+
async with httpx.AsyncClient(headers=headers, timeout=60) as client:
|
174
|
+
response = await client.post(upload_url, content=image)
|
175
|
+
response.raise_for_status()
|
176
|
+
data = response.json()
|
177
|
+
logger.debug(bjson(data))
|
172
178
|
|
173
179
|
return oss_uri
|
174
180
|
|
175
181
|
|
176
|
-
|
177
|
-
def upload_for_vod(image: bytes, upload_token: dict): # oss 跨账号不知道是否可以使用
|
182
|
+
async def upload_for_vod(image: bytes, upload_token: dict): # oss 跨账号不知道是否可以使用
|
178
183
|
# e = auth = upload_token['data']['auth'] # 豆包
|
179
184
|
data = upload_token['data']
|
180
185
|
service_id = data.get('service_id', '3jr8j4ixpe') # 即梦 3jr8j4ixpe 豆包 a9rns2rl98
|
@@ -206,12 +211,18 @@ def upload_for_vod(image: bytes, upload_token: dict): # oss 跨账号不知道
|
|
206
211
|
'x-amz-security-token': session_token,
|
207
212
|
}
|
208
213
|
# logger.debug(headers)
|
209
|
-
response = requests.get(r.api, params=params, headers=headers)
|
210
|
-
response.raise_for_status()
|
211
|
-
logger.debug(response.status_code)
|
212
|
-
response = response.json()
|
214
|
+
# response = requests.get(r.api, params=params, headers=headers)
|
215
|
+
# response.raise_for_status()
|
216
|
+
# logger.debug(response.status_code)
|
217
|
+
# response = response.json()
|
218
|
+
# logger.debug(bjson(response))
|
219
|
+
|
220
|
+
async with httpx.AsyncClient(headers=headers, params=params, timeout=120) as client:
|
221
|
+
response = await client.get(r.api)
|
222
|
+
response.raise_for_status()
|
223
|
+
response = response.json()
|
224
|
+
logger.debug(bjson(response))
|
213
225
|
|
214
|
-
logger.debug(bjson(response))
|
215
226
|
if "Result" not in response:
|
216
227
|
return
|
217
228
|
|
@@ -235,15 +246,36 @@ def upload_for_vod(image: bytes, upload_token: dict): # oss 跨账号不知道
|
|
235
246
|
# upload_url = f"https://tos-hl-x.snssdk.com/upload/v1/{oss_uri}"
|
236
247
|
upload_url = f"https://{upload_host}/upload/v1/{oss_uri}"
|
237
248
|
|
238
|
-
response = requests.post(upload_url, headers=headers, data=image)
|
239
|
-
response.raise_for_status()
|
240
|
-
response = response.json()
|
249
|
+
# response = requests.post(upload_url, headers=headers, data=image)
|
250
|
+
# response.raise_for_status()
|
251
|
+
# response = response.json()
|
252
|
+
# logger.debug(response)
|
241
253
|
|
242
|
-
|
254
|
+
async with httpx.AsyncClient(headers=headers, timeout=120) as client:
|
255
|
+
response = await client.post(upload_url, content=image)
|
256
|
+
response.raise_for_status()
|
257
|
+
data = response.json()
|
258
|
+
logger.debug(bjson(data))
|
243
259
|
|
244
260
|
return oss_uri
|
245
261
|
|
246
262
|
|
263
|
+
async def upload_for_image(image, token): # todo: 跨账号token
|
264
|
+
"""image url base64 bytes"""
|
265
|
+
|
266
|
+
upload_token = await get_upload_token(token)
|
267
|
+
image_uri = await upload(await to_bytes(image), upload_token)
|
268
|
+
return image_uri
|
269
|
+
|
270
|
+
|
271
|
+
async def upload_for_video(video, token): # 跨账号token
|
272
|
+
"""video url base64 bytes"""
|
273
|
+
|
274
|
+
upload_token = await get_upload_token(token)
|
275
|
+
uri = await upload_for_vod(await to_bytes(video), upload_token)
|
276
|
+
return uri
|
277
|
+
|
278
|
+
|
247
279
|
if __name__ == "__main__":
|
248
280
|
from meutils.apis.jimeng.common import get_upload_token
|
249
281
|
|
@@ -253,11 +285,21 @@ if __name__ == "__main__":
|
|
253
285
|
# jimeng
|
254
286
|
token = "eb4d120829cfd3ee957943f63d6152ed"
|
255
287
|
#
|
256
|
-
upload_token = arun(get_upload_token(token))
|
288
|
+
# upload_token = arun(get_upload_token(token))
|
257
289
|
|
258
290
|
#
|
259
|
-
with open("
|
260
|
-
|
291
|
+
# with open("test.jpg", "rb") as f:
|
292
|
+
# file = image = f.read()
|
293
|
+
#
|
294
|
+
# print(upload(image, upload_token))
|
295
|
+
# print(upload_for_vod(image, upload_token))
|
296
|
+
#
|
297
|
+
# with timer():
|
298
|
+
# arun(upload_for_video("https://fal.media/files/koala/8teUPbRRMtAUTORDvqy0l.mp4", token))
|
299
|
+
|
300
|
+
# with timer():
|
301
|
+
# arun(upload_for_image("https://oss.ffire.cc/files/kling_watermark.png", token))
|
261
302
|
|
262
|
-
|
263
|
-
|
303
|
+
with timer():
|
304
|
+
url = "https://oss.ffire.cc/files/lipsync.mp3"
|
305
|
+
arun(upload_for_video("https://oss.ffire.cc/files/lipsync.mp3", token))
|
meutils/apis/jimeng/images.py
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
# @Description :
|
10
10
|
|
11
11
|
from meutils.pipe import *
|
12
|
+
from meutils.caches.redis_cache import cache
|
12
13
|
|
13
14
|
from meutils.schemas.jimeng_types import BASE_URL, MODELS_MAP, FEISHU_URL
|
14
15
|
from meutils.schemas.image_types import ImageRequest
|
@@ -76,6 +77,7 @@ async def get_task(task_id, token):
|
|
76
77
|
item_list = task_info.get("item_list") # "status": 30,
|
77
78
|
|
78
79
|
status_code = task_info.get("status")
|
80
|
+
fail_msg = f"""{task_info.get("fail_msg")}"""
|
79
81
|
logger.debug(f"status: {status_code}")
|
80
82
|
|
81
83
|
"""
|
@@ -87,21 +89,33 @@ async def get_task(task_id, token):
|
|
87
89
|
|
88
90
|
task_data = sum(image_data, []) | xmap_(lambda x: {"url": x.get("image_url")})
|
89
91
|
|
90
|
-
|
92
|
+
response = TaskResponse(
|
91
93
|
task_id=task_id,
|
92
94
|
data=task_data,
|
93
|
-
message=data.get("errmsg")
|
95
|
+
message=data.get("errmsg"),
|
94
96
|
status="success" if item_list else 'processing',
|
95
97
|
code=status_code,
|
96
98
|
)
|
97
99
|
|
100
|
+
if status_code == 30:
|
101
|
+
response.status = "fail"
|
102
|
+
response.message = fail_msg
|
98
103
|
|
104
|
+
return response
|
105
|
+
|
106
|
+
|
107
|
+
# @cache: todo: cache 积分异常消耗
|
108
|
+
# @cache(ttl=3600)
|
99
109
|
async def generate(request: ImageRequest):
|
100
110
|
task_response = await create_task(request)
|
111
|
+
|
101
112
|
for i in range(1, 10):
|
102
113
|
await asyncio.sleep(max(10 / i, 1))
|
103
114
|
response = await get_task(task_response.task_id, task_response.system_fingerprint)
|
104
115
|
logger.debug(response)
|
116
|
+
if response.status.lower().startswith("fail"):
|
117
|
+
raise Exception(response.message)
|
118
|
+
|
105
119
|
if data := response.data:
|
106
120
|
return {"data": data}
|
107
121
|
|
@@ -128,13 +142,18 @@ if __name__ == '__main__':
|
|
128
142
|
|
129
143
|
# arun(get_task(task.task_id, task.system_fingerprint))
|
130
144
|
|
131
|
-
task_id = "10184295086338"
|
132
|
-
system_fingerprint = "eb4d120829cfd3ee957943f63d6152ed"
|
133
|
-
|
134
|
-
t1 = ("10184295086338", "eb4d120829cfd3ee957943f63d6152ed")
|
135
|
-
t2 = ("10184877310722", "dcf7bbc31faed9740b0bf748cd4d2c74")
|
136
|
-
t3 = ("10186352959490", "eb4d120829cfd3ee957943f63d6152ed")
|
145
|
+
# task_id = "10184295086338"
|
146
|
+
# system_fingerprint = "eb4d120829cfd3ee957943f63d6152ed"
|
147
|
+
#
|
148
|
+
# t1 = ("10184295086338", "eb4d120829cfd3ee957943f63d6152ed")
|
149
|
+
# t2 = ("10184877310722", "dcf7bbc31faed9740b0bf748cd4d2c74")
|
150
|
+
# t3 = ("10186352959490", "eb4d120829cfd3ee957943f63d6152ed")
|
151
|
+
#
|
152
|
+
# arun(get_task(*t3))
|
137
153
|
|
138
|
-
arun(
|
154
|
+
arun(generate(ImageRequest(prompt="做一个圣诞节的海报")))
|
155
|
+
# prompt = "A plump Chinese beauty wearing a wedding dress revealing her skirt and underwear is swinging on the swing,Happy smile,cleavage,Exposed thighs,Spread your legs open,Extend your leg,panties,upskirt,Barefoot,sole"
|
156
|
+
# request = ImageRequest(prompt=prompt)
|
157
|
+
# task = arun(create_task(request))
|
139
158
|
|
140
|
-
# arun(
|
159
|
+
# arun(get_task(task.task_id, task.system_fingerprint))
|
@@ -0,0 +1,236 @@
|
|
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
|
+
from meutils.pipe import *
|
17
|
+
from meutils.str_utils.json_utils import json_path
|
18
|
+
|
19
|
+
from meutils.schemas.jimeng_types import BASE_URL, MODELS_MAP, FEISHU_URL
|
20
|
+
from meutils.schemas.video_types import LipsyncVideoRquest
|
21
|
+
from meutils.schemas.task_types import TaskResponse
|
22
|
+
from meutils.apis.jimeng.common import create_draft_content, get_headers, check_token
|
23
|
+
from meutils.apis.jimeng.files import upload_for_image, upload_for_video
|
24
|
+
|
25
|
+
from meutils.config_utils.lark_utils import get_next_token_for_polling
|
26
|
+
|
27
|
+
from fake_useragent import UserAgent
|
28
|
+
|
29
|
+
ua = UserAgent()
|
30
|
+
|
31
|
+
|
32
|
+
async def create_realman_avatar(image_uri, token: str):
|
33
|
+
url = "/mweb/v1/create_realman_avatar"
|
34
|
+
headers = get_headers(url, token)
|
35
|
+
|
36
|
+
payload = {
|
37
|
+
"input_list": [
|
38
|
+
{
|
39
|
+
"image_uri": image_uri,
|
40
|
+
"submit_id": str(uuid.uuid4()),
|
41
|
+
"mode": 0
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"image_uri": image_uri,
|
45
|
+
"submit_id": str(uuid.uuid4()),
|
46
|
+
"mode": 1
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|
50
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
51
|
+
response = await client.post(url, json=payload)
|
52
|
+
response.raise_for_status()
|
53
|
+
data = response.json()
|
54
|
+
logger.debug(bjson(data)) # 1914628189186
|
55
|
+
|
56
|
+
if task_ids := json_path(data, "$..task_id"):
|
57
|
+
return task_ids
|
58
|
+
else: # task_id 解析失败
|
59
|
+
raise Exception("create_realman_avatar failed: task_id 解析失败")
|
60
|
+
|
61
|
+
# mget_generate_task
|
62
|
+
# todo: 从任务结果解析 resource_id_std, resource_id_loopy
|
63
|
+
|
64
|
+
|
65
|
+
async def get_task(task_ids):
|
66
|
+
"""
|
67
|
+
$..image_to_avatar 成功: 先检测图片or视频
|
68
|
+
:param task_ids:
|
69
|
+
:return:
|
70
|
+
"""
|
71
|
+
if isinstance(task_ids, str):
|
72
|
+
task_ids = [task_ids]
|
73
|
+
|
74
|
+
token = "916fed81175f5186a2c05375699ea40d"
|
75
|
+
|
76
|
+
|
77
|
+
url = "/mweb/v1/mget_generate_task"
|
78
|
+
headers = get_headers(url, token)
|
79
|
+
|
80
|
+
payload = {"task_id_list": task_ids}
|
81
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
82
|
+
response = await client.post(url, json=payload)
|
83
|
+
response.raise_for_status()
|
84
|
+
data = response.json()
|
85
|
+
logger.debug(bjson(data))
|
86
|
+
|
87
|
+
if messages := json_path(data, "$..image_to_avatar.message"):
|
88
|
+
if message := "".join(messages): # and "fail" in message
|
89
|
+
logger.error(message)
|
90
|
+
else:
|
91
|
+
logger.info("image_to_avatar success")
|
92
|
+
|
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
|
+
# return TaskResponse()
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
async def create_task(request: LipsyncVideoRquest, token: Optional[str] = None):
|
103
|
+
# token = token or await get_next_token_for_polling(FEISHU_URL, check_token)
|
104
|
+
token = "7c5e148d9fa858e3180c42f843c20454" # 年付
|
105
|
+
token = "916fed81175f5186a2c05375699ea40d" # 月付
|
106
|
+
|
107
|
+
url = "/mweb/v1/batch_generate_video"
|
108
|
+
|
109
|
+
headers = get_headers(url, token)
|
110
|
+
|
111
|
+
i2v_opt = {}
|
112
|
+
v2v_opt = {}
|
113
|
+
if request.video_url:
|
114
|
+
v2v_opt = {}
|
115
|
+
|
116
|
+
payload = {
|
117
|
+
"submit_id": "",
|
118
|
+
"task_extra": "{\"promptSource\":\"photo_lip_sync\",\"generateTimes\":1,\"lipSyncInfo\":{\"sourceType\":\"local-file\",\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\"},\"isUseAiGenPrompt\":false,\"batchNumber\":1}",
|
119
|
+
"http_common_info": {
|
120
|
+
"aid": 513695
|
121
|
+
},
|
122
|
+
"input": {
|
123
|
+
"seed": 3112889115,
|
124
|
+
"video_gen_inputs": [
|
125
|
+
{
|
126
|
+
"v2v_opt": {},
|
127
|
+
"i2v_opt": {
|
128
|
+
"realman_avatar": {
|
129
|
+
"enable": True,
|
130
|
+
"origin_image": {
|
131
|
+
# "width": 800,
|
132
|
+
# "height": 1200,
|
133
|
+
"image_uri": "tos-cn-i-tb4s082cfz/4dead1bfc8e84572a91f2e047016a351",
|
134
|
+
"image_url": ""
|
135
|
+
},
|
136
|
+
"origin_audio": {
|
137
|
+
# "duration": 9.976625,
|
138
|
+
"vid": "v02870g10004cu8d4r7og65j2vr5opb0"
|
139
|
+
},
|
140
|
+
|
141
|
+
"resource_id_std": "381c534f-bcef-482e-8f17-5b30b64e41a1",
|
142
|
+
"resource_id_loopy": "b9ac51cb-e26c-4b63-81d9-34ed24053032",
|
143
|
+
#
|
144
|
+
# "tts_info": "{\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\",\"source_type\":\"local-file\"}"
|
145
|
+
}
|
146
|
+
},
|
147
|
+
"audio_vid": "v02870g10004cu8d4r7og65j2vr5opb0",
|
148
|
+
"video_mode": 4
|
149
|
+
}
|
150
|
+
]
|
151
|
+
},
|
152
|
+
"mode": "workbench",
|
153
|
+
"history_option": {},
|
154
|
+
"commerce_info": {
|
155
|
+
"resource_id": "generate_video",
|
156
|
+
"resource_id_type": "str",
|
157
|
+
"resource_sub_type": "aigc",
|
158
|
+
"benefit_type": "lip_sync_avatar_std", # 5积分
|
159
|
+
# "benefit_type": "lip_sync_avatar_lively" # 10积分
|
160
|
+
},
|
161
|
+
"scene": "lip_sync_image",
|
162
|
+
"client_trace_data": {},
|
163
|
+
"submit_id_list": [
|
164
|
+
str(uuid.uuid4())
|
165
|
+
]
|
166
|
+
}
|
167
|
+
|
168
|
+
# if request.image_url:
|
169
|
+
# i2v_opt = {
|
170
|
+
# "realman_avatar": {
|
171
|
+
# "enable": True,
|
172
|
+
# "origin_image": {
|
173
|
+
# "width": 800,
|
174
|
+
# "height": 1200, ######## 没必要把
|
175
|
+
# "image_uri": request.image_url,
|
176
|
+
# "image_url": ""
|
177
|
+
# },
|
178
|
+
# "resource_id_loopy": "9c397499-a59f-47b5-9bfd-e1397ec62f61",
|
179
|
+
# "resource_id_std": "0a8c8d72-5543-4e9e-8843-c03fe5b3a8c7",
|
180
|
+
# "origin_audio": {
|
181
|
+
# "duration": 9.976625,
|
182
|
+
# "vid": "v03870g10004cu6vpgfog65nc9ivupg0"
|
183
|
+
# },
|
184
|
+
# "tts_info": "{\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\",\"source_type\":\"local-file\"}"
|
185
|
+
# }
|
186
|
+
# }
|
187
|
+
#
|
188
|
+
# payload = {
|
189
|
+
# "submit_id": "",
|
190
|
+
# "task_extra": "{\"promptSource\":\"photo_lip_sync\",\"generateTimes\":1,\"lipSyncInfo\":{\"sourceType\":\"local-file\",\"name\":\"vyFWygmZsIZlUO4s0nr2n.wav\"},\"isUseAiGenPrompt\":false,\"batchNumber\":1}",
|
191
|
+
# "http_common_info": {
|
192
|
+
# "aid": 513695
|
193
|
+
# },
|
194
|
+
# "input": {
|
195
|
+
# "seed": 2032846910,
|
196
|
+
# "video_gen_inputs": [
|
197
|
+
# {
|
198
|
+
# "v2v_opt": v2v_opt,
|
199
|
+
# "i2v_opt": i2v_opt,
|
200
|
+
# "audio_vid": "v03870g10004cu6vpgfog65nc9ivupg0",
|
201
|
+
# "video_mode": 4
|
202
|
+
# }
|
203
|
+
# ]
|
204
|
+
# },
|
205
|
+
# "mode": "workbench",
|
206
|
+
# "history_option": {},
|
207
|
+
# "commerce_info": {
|
208
|
+
# "resource_id": "generate_video",
|
209
|
+
# "resource_id_type": "str",
|
210
|
+
# "resource_sub_type": "aigc",
|
211
|
+
# "benefit_type": "lip_sync_avatar_std"
|
212
|
+
# },
|
213
|
+
# "scene": "lip_sync_image",
|
214
|
+
# "client_trace_data": {},
|
215
|
+
# "submit_id_list": [
|
216
|
+
# "4717038e-f4fd-4c1c-b5a5-39ae4118099c"
|
217
|
+
# ]
|
218
|
+
# }
|
219
|
+
|
220
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
221
|
+
response = await client.post(url, json=payload)
|
222
|
+
response.raise_for_status()
|
223
|
+
data = response.json()
|
224
|
+
logger.debug(bjson(data))
|
225
|
+
|
226
|
+
if task_ids := json_path(data, "$..task.task_id"):
|
227
|
+
task_id = task_ids[0]
|
228
|
+
return TaskResponse(task_id=task_id, system_fingerprint=token)
|
229
|
+
|
230
|
+
|
231
|
+
if __name__ == '__main__':
|
232
|
+
# image_uri = "tos-cn-i-tb4s082cfz/387649a361e546f89549bd3510ab926d"
|
233
|
+
# task_ids = arun(create_realman_avatar(image_uri, token="7c5e148d9fa858e3180c42f843c20454"))
|
234
|
+
# arun(mget_generate_task(task_ids))
|
235
|
+
r = arun(create_task(LipsyncVideoRquest()))
|
236
|
+
arun(get_task(r.task_id))
|
meutils/apis/oneapi/user.py
CHANGED
@@ -20,6 +20,7 @@ token = os.environ.get("CHATFIRE_ONEAPI_TOKEN")
|
|
20
20
|
|
21
21
|
headers = {
|
22
22
|
"Authorization": f"Bearer {token}",
|
23
|
+
'rix-api-user': '1'
|
23
24
|
}
|
24
25
|
|
25
26
|
|
@@ -55,6 +56,7 @@ async def get_api_key_log(api_key: str) -> Optional[list]: # 日志查询会超
|
|
55
56
|
|
56
57
|
@alru_cache(ttl=60)
|
57
58
|
async def get_user(user_id):
|
59
|
+
|
58
60
|
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=30) as client:
|
59
61
|
response = await client.get(f"/api/user/{user_id}")
|
60
62
|
# logger.debug(response.text)
|
@@ -97,4 +99,4 @@ if __name__ == '__main__':
|
|
97
99
|
# arun(put_user(payload, -1))
|
98
100
|
|
99
101
|
# arun(get_api_key_log('sk-gpoH1z3G6nHovD8MY40i6xx5tsC1vbh7B3Aao2jmejYNoKhv'))
|
100
|
-
|
102
|
+
arun(get_user_money("sk-gpoH1z3G6nHovD8MY40i6xx5tsC1vbh7B3Aao2jmejYNoKhv"))
|
meutils/data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2025.01.
|
1
|
+
2025.01.23.10.16.28
|