MeUtils 2025.6.6.18.22.44__py3-none-any.whl → 2025.6.9.9.17.14__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.6.6.18.22.44.dist-info → MeUtils-2025.6.9.9.17.14.dist-info}/METADATA +261 -261
- {MeUtils-2025.6.6.18.22.44.dist-info → MeUtils-2025.6.9.9.17.14.dist-info}/RECORD +25 -16
- meutils/apis/fal/images.py +11 -4
- meutils/apis/hailuoai/videos.py +3 -2
- meutils/apis/jimeng/common.py +1 -1
- meutils/apis/jimeng/images.py +0 -1
- meutils/apis/jimeng_global/__init__.py +10 -0
- meutils/apis/jimeng_global/audio.py +192 -0
- meutils/apis/jimeng_global/common.py +218 -0
- meutils/apis/jimeng_global/doubao_images.py +70 -0
- meutils/apis/jimeng_global/doubao_utils.py +175 -0
- meutils/apis/jimeng_global/files.py +368 -0
- meutils/apis/jimeng_global/images.py +744 -0
- meutils/apis/jimeng_global/videos.py +187 -0
- meutils/apis/jimeng_global/videos_videos.py +334 -0
- meutils/data/VERSION +1 -1
- meutils/schemas/image_types.py +3 -1
- meutils/schemas/jimeng_types.py +1 -0
- meutils/schemas/oneapi/common.py +4 -2
- meutils/str_utils/__init__.py +43 -6
- meutils/str_utils/regular_expression.py +1 -0
- {MeUtils-2025.6.6.18.22.44.dist-info → MeUtils-2025.6.9.9.17.14.dist-info}/LICENSE +0 -0
- {MeUtils-2025.6.6.18.22.44.dist-info → MeUtils-2025.6.9.9.17.14.dist-info}/WHEEL +0 -0
- {MeUtils-2025.6.6.18.22.44.dist-info → MeUtils-2025.6.9.9.17.14.dist-info}/entry_points.txt +0 -0
- {MeUtils-2025.6.6.18.22.44.dist-info → MeUtils-2025.6.9.9.17.14.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,744 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Project : AI. @by PyCharm
|
4
|
+
# @File : images
|
5
|
+
# @Time : 2024/12/16 17:46
|
6
|
+
# @Author : betterme
|
7
|
+
# @WeChat : meutils
|
8
|
+
# @Software : PyCharm
|
9
|
+
# @Description :
|
10
|
+
"""
|
11
|
+
guidance 控制精细度 => sample_strength 0-1 数值越大生成的效果质量越好,耗时会更久
|
12
|
+
paths: ["/mweb/v1/generate", "/mweb/v1/super_resolution", "/mweb/v1/painting", "/commerce/v1/subscription/make_unauto_order", "/commerce/v1/benefits/credit_receive", "/commerce/v1/purchase/make_order", "/mweb/v1/get_explore", "/mweb/v1/feed_short_video", "/mweb/v1/feed", "/mweb/v1/get_homepage", "/mweb/v1/get_weekly_challenge_work_list", "/mweb/v1/mget_item_info", "/mweb/v1/get_item_info", "/mweb/v1/get_history_by_ids", "/mweb/search/v1/search"],
|
13
|
+
|
14
|
+
"""
|
15
|
+
|
16
|
+
from meutils.pipe import *
|
17
|
+
from meutils.caches import rcache
|
18
|
+
|
19
|
+
from meutils.decorators.retry import retrying
|
20
|
+
from meutils.notice.feishu import send_message_for_images
|
21
|
+
|
22
|
+
from meutils.schemas.jimeng_types import BASE_URL_GLOBAL as BASE_URL, MODELS_MAP, FEISHU_URL
|
23
|
+
from meutils.schemas.image_types import ImageRequest
|
24
|
+
from meutils.schemas.task_types import TaskResponse
|
25
|
+
from meutils.apis.jimeng.common import get_headers, check_token
|
26
|
+
from meutils.apis.jimeng.files import upload_for_image
|
27
|
+
from meutils.str_utils.regular_expression import parse_url
|
28
|
+
|
29
|
+
from meutils.config_utils.lark_utils import get_next_token_for_polling
|
30
|
+
from fastapi import status, HTTPException
|
31
|
+
|
32
|
+
from fake_useragent import UserAgent
|
33
|
+
|
34
|
+
ua = UserAgent()
|
35
|
+
|
36
|
+
VERSION = "3.2.5"
|
37
|
+
|
38
|
+
|
39
|
+
#
|
40
|
+
async def create_draft_content(request: ImageRequest, token: str):
|
41
|
+
"""
|
42
|
+
创建草稿内容
|
43
|
+
"""
|
44
|
+
# 参考人物
|
45
|
+
face_recognize_data = request.controls.get("face_recognize_data", {})
|
46
|
+
image_uri = face_recognize_data.pop("image_uri", None)
|
47
|
+
|
48
|
+
request.model = MODELS_MAP.get(request.model, MODELS_MAP["default"])
|
49
|
+
|
50
|
+
height = width = 1328
|
51
|
+
if 'x' in request.size:
|
52
|
+
width, height = map(int, request.size.split('x'))
|
53
|
+
|
54
|
+
main_component_id = str(uuid.uuid4())
|
55
|
+
if (urls := parse_url(request.prompt)) or image_uri: # 图生 # todo: image base64
|
56
|
+
request.model = "high_aes_general_v20_L:general_v2.0_L" # 2.1不支持图片编辑 某些不支持
|
57
|
+
|
58
|
+
if image_uri:
|
59
|
+
pass
|
60
|
+
|
61
|
+
else:
|
62
|
+
url = urls[-1]
|
63
|
+
image_uri = await upload_for_image(url, token)
|
64
|
+
|
65
|
+
request.prompt = request.prompt.replace(url, '')
|
66
|
+
|
67
|
+
component = {
|
68
|
+
"type": "image_base_component",
|
69
|
+
"id": main_component_id,
|
70
|
+
"min_version": "3.0.2",
|
71
|
+
"generate_type": "blend",
|
72
|
+
"aigc_mode": "workbench",
|
73
|
+
"abilities": {
|
74
|
+
"type": "",
|
75
|
+
"id": str(uuid.uuid4()),
|
76
|
+
"blend": {
|
77
|
+
"type": "",
|
78
|
+
"id": str(uuid.uuid4()),
|
79
|
+
"core_param": {
|
80
|
+
"type": "",
|
81
|
+
"id": str(uuid.uuid4()),
|
82
|
+
"model": request.model,
|
83
|
+
"prompt": f"##{request.prompt}",
|
84
|
+
"sample_strength": 0.5,
|
85
|
+
"image_ratio": 1,
|
86
|
+
"large_image_info": {
|
87
|
+
"type": "",
|
88
|
+
"id": str(uuid.uuid4()),
|
89
|
+
"height": height,
|
90
|
+
"width": width,
|
91
|
+
|
92
|
+
# "resolution_type": "2k"
|
93
|
+
},
|
94
|
+
},
|
95
|
+
"ability_list": [
|
96
|
+
{
|
97
|
+
"type": "",
|
98
|
+
"id": str(uuid.uuid4()),
|
99
|
+
"name": "byte_edit", # bg_paint face_gan
|
100
|
+
"image_uri_list": [
|
101
|
+
image_uri
|
102
|
+
],
|
103
|
+
"image_list": [
|
104
|
+
{
|
105
|
+
"type": "image",
|
106
|
+
"id": str(uuid.uuid4()),
|
107
|
+
"source_from": "upload",
|
108
|
+
"platform_type": 1,
|
109
|
+
"name": "",
|
110
|
+
"image_uri": image_uri,
|
111
|
+
"width": 0,
|
112
|
+
"height": 0,
|
113
|
+
"format": "",
|
114
|
+
"uri": image_uri
|
115
|
+
}
|
116
|
+
],
|
117
|
+
|
118
|
+
"strength": 0.5
|
119
|
+
}
|
120
|
+
],
|
121
|
+
"history_option": {
|
122
|
+
"type": "",
|
123
|
+
"id": str(uuid.uuid4()),
|
124
|
+
},
|
125
|
+
"prompt_placeholder_info_list": [
|
126
|
+
{
|
127
|
+
"type": "",
|
128
|
+
"id": str(uuid.uuid4()),
|
129
|
+
"ability_index": 0
|
130
|
+
}
|
131
|
+
],
|
132
|
+
"postedit_param": {
|
133
|
+
"type": "",
|
134
|
+
"id": str(uuid.uuid4()),
|
135
|
+
"generate_type": 0
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
if face_recognize_data:
|
142
|
+
face_recognize_data['name'] = "face_gan"
|
143
|
+
component["abilities"]["blend"]["ability_list"][0].update(face_recognize_data)
|
144
|
+
|
145
|
+
else: # 文生
|
146
|
+
|
147
|
+
component = {
|
148
|
+
"type": "image_base_component",
|
149
|
+
"id": main_component_id,
|
150
|
+
"min_version": "3.0.2",
|
151
|
+
"generate_type": "generate",
|
152
|
+
"aigc_mode": "workbench",
|
153
|
+
# 国际版
|
154
|
+
"metadata": {
|
155
|
+
"type": "",
|
156
|
+
"id": str(uuid.uuid4()),
|
157
|
+
"created_platform": 3,
|
158
|
+
"created_platform_version": "",
|
159
|
+
"created_time_in_ms": f"{time.time() * 1000}//1",
|
160
|
+
"created_did": ""
|
161
|
+
},
|
162
|
+
"abilities": {
|
163
|
+
"type": "",
|
164
|
+
"id": str(uuid.uuid4()),
|
165
|
+
"generate": {
|
166
|
+
"type": "",
|
167
|
+
"id": str(uuid.uuid4()),
|
168
|
+
"core_param": {
|
169
|
+
"type": "",
|
170
|
+
"id": str(uuid.uuid4()),
|
171
|
+
"model": request.model,
|
172
|
+
"prompt": request.prompt,
|
173
|
+
"negative_prompt": request.negative_prompt or "",
|
174
|
+
"seed": request.seed or 1192648548,
|
175
|
+
"sample_strength": request.guidance or 0.5, # 精细度
|
176
|
+
"image_ratio": 1,
|
177
|
+
"large_image_info": {
|
178
|
+
"type": "",
|
179
|
+
"id": str(uuid.uuid4()),
|
180
|
+
"height": height,
|
181
|
+
"width": width,
|
182
|
+
|
183
|
+
"resolution_type": "1k"
|
184
|
+
}
|
185
|
+
},
|
186
|
+
"history_option": {
|
187
|
+
"type": "",
|
188
|
+
"id": str(uuid.uuid4()),
|
189
|
+
}
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
component = {
|
194
|
+
"type": "image_base_component",
|
195
|
+
"id": main_component_id,
|
196
|
+
"min_version": "3.0.2",
|
197
|
+
"metadata": {
|
198
|
+
"type": "",
|
199
|
+
"id": "85295e81-9b68-fba4-6570-81fc96c4b76e",
|
200
|
+
"created_platform": 3,
|
201
|
+
"created_platform_version": "",
|
202
|
+
"created_time_in_ms": "1749271549726",
|
203
|
+
"created_did": ""
|
204
|
+
},
|
205
|
+
"generate_type": "generate",
|
206
|
+
"aigc_mode": "workbench",
|
207
|
+
"abilities": {
|
208
|
+
"type": "",
|
209
|
+
"id": "91c763e9-1574-162d-1e7a-3356200dbc00",
|
210
|
+
"generate": {
|
211
|
+
"type": "",
|
212
|
+
"id": "3862c659-7761-841a-95a1-5d02b5326e72",
|
213
|
+
"core_param": {
|
214
|
+
"type": "",
|
215
|
+
"id": "fcbc04a9-26ba-c890-c753-39d2a0ff9ef7",
|
216
|
+
"model": "high_aes_general_v30l:general_v3.0_18b",
|
217
|
+
"prompt": "a dog",
|
218
|
+
"negative_prompt": "",
|
219
|
+
"seed": 1192648548,
|
220
|
+
"sample_strength": 0.5,
|
221
|
+
"image_ratio": 1,
|
222
|
+
"large_image_info": {
|
223
|
+
"type": "",
|
224
|
+
"id": "04242843-bfee-0584-9162-a611c5ff1b54",
|
225
|
+
"height": 1328,
|
226
|
+
"width": 1328,
|
227
|
+
"resolution_type": "1k"
|
228
|
+
}
|
229
|
+
},
|
230
|
+
"history_option": {
|
231
|
+
"type": "",
|
232
|
+
"id": "4e5867c5-06e9-c101-a1a8-bb972623d701"
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
draft_content = {
|
239
|
+
"type": "draft",
|
240
|
+
"id": str(uuid.uuid4()),
|
241
|
+
"min_version": "3.0.2",
|
242
|
+
"min_features": [],
|
243
|
+
"is_from_tsn": True,
|
244
|
+
"version": VERSION,
|
245
|
+
"main_component_id": main_component_id,
|
246
|
+
"component_list": [component]
|
247
|
+
}
|
248
|
+
logger.debug(draft_content)
|
249
|
+
# logger.debug(bjson(draft_content))
|
250
|
+
|
251
|
+
return draft_content
|
252
|
+
|
253
|
+
|
254
|
+
def key_builder(*args, **kwargs):
|
255
|
+
logger.debug(args)
|
256
|
+
logger.debug(kwargs)
|
257
|
+
|
258
|
+
return args[1].prompt
|
259
|
+
|
260
|
+
|
261
|
+
@retrying()
|
262
|
+
@rcache(ttl=1 * 1 * 3600, serializer="pickle", key_builder=lambda *args, **kwargs: f"{args[1].seed} {args[1].prompt}")
|
263
|
+
async def create_task(request: ImageRequest, token: Optional[str] = None): # todo: 图片
|
264
|
+
token = token or await get_next_token_for_polling(FEISHU_URL, check_token)
|
265
|
+
|
266
|
+
send_message_for_images(request, __name__)
|
267
|
+
|
268
|
+
url = "/mweb/v1/aigc_draft/generate"
|
269
|
+
|
270
|
+
headers = get_headers(url, token)
|
271
|
+
|
272
|
+
if "http" in request.prompt: # 图生
|
273
|
+
request.model = "high_aes_general_v20_L:general_v2.0_L"
|
274
|
+
|
275
|
+
draft_content = await create_draft_content(request, token)
|
276
|
+
|
277
|
+
logger.debug(json.dumps(draft_content))
|
278
|
+
|
279
|
+
payload = {
|
280
|
+
"extend": {
|
281
|
+
"root_model": request.model,
|
282
|
+
"template_id": ""
|
283
|
+
},
|
284
|
+
"submit_id": str(uuid.uuid4()),
|
285
|
+
"metrics_extra": "{\"templateId\":\"\",\"generateCount\":1,\"promptSource\":\"custom\",\"templateSource\":\"\",\"lastRequestId\":\"\",\"originRequestId\":\"\"}",
|
286
|
+
"draft_content": json.dumps(draft_content),
|
287
|
+
# "http_common_info": {
|
288
|
+
# "aid": 513695
|
289
|
+
# }
|
290
|
+
}
|
291
|
+
# logger.debug(bjson(payload))
|
292
|
+
# payload = {"extend": {"root_model": "high_aes_general_v30l:general_v3.0_18b", "template_id": ""},
|
293
|
+
# "submit_id": "6e356f64-2bc3-45c7-83b6-64371bac9b64",
|
294
|
+
# "metrics_extra": "{\"templateId\":\"\",\"generateCount\":1,\"promptSource\":\"custom\",\"templateSource\":\"\",\"lastRequestId\":\"\",\"originRequestId\":\"\"}",
|
295
|
+
# "draft_content": "{\"type\":\"draft\",\"id\":\"0a47b141-8c2a-f4ce-ae51-5670688d3fdf\",\"min_version\":\"3.0.2\",\"min_features\":[],\"is_from_tsn\":true,\"version\":\"3.2.5\",\"main_component_id\":\"d7cf2d3f-db61-9775-2970-b3be2c193a71\",\"component_list\":[{\"type\":\"image_base_component\",\"id\":\"d7cf2d3f-db61-9775-2970-b3be2c193a71\",\"min_version\":\"3.0.2\",\"metadata\":{\"type\":\"\",\"id\":\"85295e81-9b68-fba4-6570-81fc96c4b76e\",\"created_platform\":3,\"created_platform_version\":\"\",\"created_time_in_ms\":\"1749271549726\",\"created_did\":\"\"},\"generate_type\":\"generate\",\"aigc_mode\":\"workbench\",\"abilities\":{\"type\":\"\",\"id\":\"91c763e9-1574-162d-1e7a-3356200dbc00\",\"generate\":{\"type\":\"\",\"id\":\"3862c659-7761-841a-95a1-5d02b5326e72\",\"core_param\":{\"type\":\"\",\"id\":\"fcbc04a9-26ba-c890-c753-39d2a0ff9ef7\",\"model\":\"high_aes_general_v30l:general_v3.0_18b\",\"prompt\":\"a dog\",\"negative_prompt\":\"\",\"seed\":1192648548,\"sample_strength\":0.5,\"image_ratio\":1,\"large_image_info\":{\"type\":\"\",\"id\":\"04242843-bfee-0584-9162-a611c5ff1b54\",\"height\":1328,\"width\":1328,\"resolution_type\":\"1k\"}},\"history_option\":{\"type\":\"\",\"id\":\"4e5867c5-06e9-c101-a1a8-bb972623d701\"}}}}]}"}
|
296
|
+
|
297
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
298
|
+
response = await client.post(url, json=payload)
|
299
|
+
response.raise_for_status()
|
300
|
+
|
301
|
+
data = response.json()
|
302
|
+
logger.debug(bjson(data))
|
303
|
+
|
304
|
+
# {
|
305
|
+
# "ret": "1000",
|
306
|
+
# "errmsg": "invalid parameter",
|
307
|
+
# "systime": "1744354538",
|
308
|
+
# "logid": "20250411145538E30D2FF8347A9A710F49",
|
309
|
+
# "data": {
|
310
|
+
# "aigc_data": null,
|
311
|
+
# "fail_code": "",
|
312
|
+
# "fail_starling_key": "",
|
313
|
+
# "fail_starling_message": ""
|
314
|
+
# }
|
315
|
+
# }
|
316
|
+
|
317
|
+
aigc_data = (data.get("data") or {}).get("aigc_data") or {}
|
318
|
+
|
319
|
+
logger.debug(bjson(aigc_data))
|
320
|
+
|
321
|
+
if task_id := aigc_data.get("history_record_id"): # bug
|
322
|
+
return TaskResponse(task_id=task_id, system_fingerprint=token)
|
323
|
+
else:
|
324
|
+
|
325
|
+
# {
|
326
|
+
# "ret": "1018",
|
327
|
+
# "errmsg": "account punish limit ai generate",
|
328
|
+
# "systime": "1737962056",
|
329
|
+
# "logid": "202501271514162E3DA8ECD70A3EE1400F",
|
330
|
+
# "data": null
|
331
|
+
# }
|
332
|
+
|
333
|
+
raise HTTPException(
|
334
|
+
status_code=status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS,
|
335
|
+
detail=f"可能触发内容审核,请联系管理员:{data.get('errmsg')}"
|
336
|
+
)
|
337
|
+
|
338
|
+
|
339
|
+
@retrying(max_retries=3, min=3)
|
340
|
+
async def get_task(task_id, token):
|
341
|
+
url = "/mweb/v1/get_history_by_ids"
|
342
|
+
headers = get_headers(url, token)
|
343
|
+
|
344
|
+
payload = {
|
345
|
+
"history_ids": [
|
346
|
+
task_id
|
347
|
+
]
|
348
|
+
}
|
349
|
+
|
350
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
351
|
+
response = await client.post(url, json=payload)
|
352
|
+
response.raise_for_status()
|
353
|
+
|
354
|
+
logger.debug(response.text)
|
355
|
+
|
356
|
+
task_info = {}
|
357
|
+
if response.text:
|
358
|
+
data = response.json()
|
359
|
+
logger.debug(bjson(data))
|
360
|
+
task_info = (data.get("data") or {}).get(task_id, {})
|
361
|
+
else:
|
362
|
+
logger.debug("走 /mweb/v1/get_history")
|
363
|
+
|
364
|
+
data = await get_task_plus(task_id, token)
|
365
|
+
|
366
|
+
records_list = (data.get("data") or {}).get("records_list", [])
|
367
|
+
|
368
|
+
for record in records_list:
|
369
|
+
if record.get("history_record_id") == task_id:
|
370
|
+
task_info = record
|
371
|
+
|
372
|
+
# {'ret': '1015', 'errmsg': 'login error', 'systime': '1734524280', 'logid': '20241218201800AC3267447B287E9E6C46', 'data': None}
|
373
|
+
item_list = task_info.get("item_list", []) # "status": 30,
|
374
|
+
|
375
|
+
status_code = task_info.get("status")
|
376
|
+
fail_msg = f"""{task_info.get("fail_msg")}"""
|
377
|
+
|
378
|
+
logger.debug(f"status: {status_code}")
|
379
|
+
|
380
|
+
# 敏感词存储
|
381
|
+
# if status_code != 50:
|
382
|
+
# send_message_for_images(task_info, __name__)
|
383
|
+
|
384
|
+
"""
|
385
|
+
"status": 30, # 内容审核
|
386
|
+
"status": 50,
|
387
|
+
"""
|
388
|
+
|
389
|
+
image_data = map(lambda x: x.get("image", {}).get("large_images", []), item_list)
|
390
|
+
|
391
|
+
task_data = sum(image_data, []) | xmap_(lambda x: {"url": x.get("image_url")})
|
392
|
+
|
393
|
+
response = TaskResponse(
|
394
|
+
task_id=task_id,
|
395
|
+
data=task_data,
|
396
|
+
message=data.get("errmsg"),
|
397
|
+
status="success" if item_list else 'processing',
|
398
|
+
code=status_code,
|
399
|
+
)
|
400
|
+
|
401
|
+
if status_code == 30:
|
402
|
+
response.status = "fail"
|
403
|
+
response.message = fail_msg
|
404
|
+
|
405
|
+
return response
|
406
|
+
|
407
|
+
|
408
|
+
@retrying(max_retries=3, min=3)
|
409
|
+
async def get_task_plus(task_id, token):
|
410
|
+
url = "/mweb/v1/get_history"
|
411
|
+
headers = get_headers(url, token)
|
412
|
+
|
413
|
+
params = {
|
414
|
+
"aid": 513695,
|
415
|
+
"da_version": "3.2.2",
|
416
|
+
"aigc_features": "app_lip_sync",
|
417
|
+
}
|
418
|
+
|
419
|
+
payload = {
|
420
|
+
"count": 20,
|
421
|
+
"history_type_list": [
|
422
|
+
1,
|
423
|
+
4,
|
424
|
+
5,
|
425
|
+
6,
|
426
|
+
7,
|
427
|
+
8
|
428
|
+
],
|
429
|
+
"direction": 1,
|
430
|
+
"mode": "workbench",
|
431
|
+
"image_info": {
|
432
|
+
"width": 2048,
|
433
|
+
"height": 2048,
|
434
|
+
"format": "webp",
|
435
|
+
"image_scene_list": [
|
436
|
+
{
|
437
|
+
"scene": "smart_crop",
|
438
|
+
"width": 240,
|
439
|
+
"height": 240,
|
440
|
+
"uniq_key": "smart_crop-w:240-h:240",
|
441
|
+
"format": "webp"
|
442
|
+
},
|
443
|
+
{
|
444
|
+
"scene": "smart_crop",
|
445
|
+
"width": 320,
|
446
|
+
"height": 320,
|
447
|
+
"uniq_key": "smart_crop-w:320-h:320",
|
448
|
+
"format": "webp"
|
449
|
+
},
|
450
|
+
{
|
451
|
+
"scene": "smart_crop",
|
452
|
+
"width": 480,
|
453
|
+
"height": 480,
|
454
|
+
"uniq_key": "smart_crop-w:480-h:480",
|
455
|
+
"format": "webp"
|
456
|
+
},
|
457
|
+
{
|
458
|
+
"scene": "smart_crop",
|
459
|
+
"width": 480,
|
460
|
+
"height": 320,
|
461
|
+
"uniq_key": "smart_crop-w:480-h:320",
|
462
|
+
"format": "webp"
|
463
|
+
},
|
464
|
+
{
|
465
|
+
"scene": "smart_crop",
|
466
|
+
"width": 240,
|
467
|
+
"height": 160,
|
468
|
+
"uniq_key": "smart_crop-w:240-h:160",
|
469
|
+
"format": "webp"
|
470
|
+
},
|
471
|
+
{
|
472
|
+
"scene": "smart_crop",
|
473
|
+
"width": 160,
|
474
|
+
"height": 213,
|
475
|
+
"uniq_key": "smart_crop-w:160-h:213",
|
476
|
+
"format": "webp"
|
477
|
+
},
|
478
|
+
{
|
479
|
+
"scene": "smart_crop",
|
480
|
+
"width": 320,
|
481
|
+
"height": 427,
|
482
|
+
"uniq_key": "smart_crop-w:320-h:427",
|
483
|
+
"format": "webp"
|
484
|
+
},
|
485
|
+
{
|
486
|
+
"scene": "loss",
|
487
|
+
"width": 1080,
|
488
|
+
"height": 1080,
|
489
|
+
"uniq_key": "1080",
|
490
|
+
"format": "webp"
|
491
|
+
},
|
492
|
+
{
|
493
|
+
"scene": "loss",
|
494
|
+
"width": 900,
|
495
|
+
"height": 900,
|
496
|
+
"uniq_key": "900",
|
497
|
+
"format": "webp"
|
498
|
+
},
|
499
|
+
{
|
500
|
+
"scene": "loss",
|
501
|
+
"width": 720,
|
502
|
+
"height": 720,
|
503
|
+
"uniq_key": "720",
|
504
|
+
"format": "webp"
|
505
|
+
},
|
506
|
+
{
|
507
|
+
"scene": "loss",
|
508
|
+
"width": 480,
|
509
|
+
"height": 480,
|
510
|
+
"uniq_key": "480",
|
511
|
+
"format": "webp"
|
512
|
+
},
|
513
|
+
{
|
514
|
+
"scene": "loss",
|
515
|
+
"width": 360,
|
516
|
+
"height": 360,
|
517
|
+
"uniq_key": "360",
|
518
|
+
"format": "webp"
|
519
|
+
},
|
520
|
+
{
|
521
|
+
"scene": "normal",
|
522
|
+
"width": 2400,
|
523
|
+
"height": 2400,
|
524
|
+
"uniq_key": "2400",
|
525
|
+
"format": "webp"
|
526
|
+
}
|
527
|
+
]
|
528
|
+
},
|
529
|
+
"origin_image_info": {
|
530
|
+
"width": 96,
|
531
|
+
"format": "webp",
|
532
|
+
"image_scene_list": [
|
533
|
+
{
|
534
|
+
"scene": "smart_crop",
|
535
|
+
"width": 240,
|
536
|
+
"height": 240,
|
537
|
+
"uniq_key": "smart_crop-w:240-h:240",
|
538
|
+
"format": "webp"
|
539
|
+
},
|
540
|
+
{
|
541
|
+
"scene": "smart_crop",
|
542
|
+
"width": 320,
|
543
|
+
"height": 320,
|
544
|
+
"uniq_key": "smart_crop-w:320-h:320",
|
545
|
+
"format": "webp"
|
546
|
+
},
|
547
|
+
{
|
548
|
+
"scene": "smart_crop",
|
549
|
+
"width": 480,
|
550
|
+
"height": 480,
|
551
|
+
"uniq_key": "smart_crop-w:480-h:480",
|
552
|
+
"format": "webp"
|
553
|
+
},
|
554
|
+
{
|
555
|
+
"scene": "smart_crop",
|
556
|
+
"width": 480,
|
557
|
+
"height": 320,
|
558
|
+
"uniq_key": "smart_crop-w:480-h:320",
|
559
|
+
"format": "webp"
|
560
|
+
},
|
561
|
+
{
|
562
|
+
"scene": "smart_crop",
|
563
|
+
"width": 240,
|
564
|
+
"height": 160,
|
565
|
+
"uniq_key": "smart_crop-w:240-h:160",
|
566
|
+
"format": "webp"
|
567
|
+
},
|
568
|
+
{
|
569
|
+
"scene": "smart_crop",
|
570
|
+
"width": 160,
|
571
|
+
"height": 213,
|
572
|
+
"uniq_key": "smart_crop-w:160-h:213",
|
573
|
+
"format": "webp"
|
574
|
+
},
|
575
|
+
{
|
576
|
+
"scene": "smart_crop",
|
577
|
+
"width": 320,
|
578
|
+
"height": 427,
|
579
|
+
"uniq_key": "smart_crop-w:320-h:427",
|
580
|
+
"format": "webp"
|
581
|
+
},
|
582
|
+
{
|
583
|
+
"scene": "loss",
|
584
|
+
"width": 1080,
|
585
|
+
"height": 1080,
|
586
|
+
"uniq_key": "1080",
|
587
|
+
"format": "webp"
|
588
|
+
},
|
589
|
+
{
|
590
|
+
"scene": "loss",
|
591
|
+
"width": 900,
|
592
|
+
"height": 900,
|
593
|
+
"uniq_key": "900",
|
594
|
+
"format": "webp"
|
595
|
+
},
|
596
|
+
{
|
597
|
+
"scene": "loss",
|
598
|
+
"width": 720,
|
599
|
+
"height": 720,
|
600
|
+
"uniq_key": "720",
|
601
|
+
"format": "webp"
|
602
|
+
},
|
603
|
+
{
|
604
|
+
"scene": "loss",
|
605
|
+
"width": 480,
|
606
|
+
"height": 480,
|
607
|
+
"uniq_key": "480",
|
608
|
+
"format": "webp"
|
609
|
+
},
|
610
|
+
{
|
611
|
+
"scene": "loss",
|
612
|
+
"width": 360,
|
613
|
+
"height": 360,
|
614
|
+
"uniq_key": "360",
|
615
|
+
"format": "webp"
|
616
|
+
},
|
617
|
+
{
|
618
|
+
"scene": "normal",
|
619
|
+
"width": 2400,
|
620
|
+
"height": 2400,
|
621
|
+
"uniq_key": "2400",
|
622
|
+
"format": "webp"
|
623
|
+
}
|
624
|
+
]
|
625
|
+
},
|
626
|
+
"history_option": {
|
627
|
+
"story_id": "",
|
628
|
+
"multi_size_image_config": [
|
629
|
+
{
|
630
|
+
"height": 100,
|
631
|
+
"width": 100,
|
632
|
+
"format": "webp"
|
633
|
+
},
|
634
|
+
{
|
635
|
+
"height": 360,
|
636
|
+
"width": 360,
|
637
|
+
"format": "webp"
|
638
|
+
},
|
639
|
+
{
|
640
|
+
"height": 720,
|
641
|
+
"width": 720,
|
642
|
+
"format": "webp"
|
643
|
+
}
|
644
|
+
]
|
645
|
+
},
|
646
|
+
"is_pack_origin": True
|
647
|
+
}
|
648
|
+
|
649
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers=headers, timeout=60) as client:
|
650
|
+
response = await client.post(url, json=payload, params=params)
|
651
|
+
response.raise_for_status()
|
652
|
+
|
653
|
+
return response.json()
|
654
|
+
|
655
|
+
|
656
|
+
# @cache: todo: cache 积分异常消耗
|
657
|
+
# @cache(ttl=3600)
|
658
|
+
async def generate(request: ImageRequest):
|
659
|
+
# logger.debug(request)
|
660
|
+
|
661
|
+
task_response = await create_task(request)
|
662
|
+
|
663
|
+
for i in range(1, 15):
|
664
|
+
await asyncio.sleep(max(15 / i, 5))
|
665
|
+
response = await get_task(task_response.task_id, task_response.system_fingerprint)
|
666
|
+
logger.debug(f"{task_response.task_id, task_response.system_fingerprint}")
|
667
|
+
logger.debug(response)
|
668
|
+
if response.status.lower().startswith("fail"):
|
669
|
+
raise HTTPException(
|
670
|
+
status_code=status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS,
|
671
|
+
detail=response.message
|
672
|
+
)
|
673
|
+
|
674
|
+
if data := response.data:
|
675
|
+
return {"data": data}
|
676
|
+
|
677
|
+
|
678
|
+
if __name__ == '__main__':
|
679
|
+
# token = "eb4d120829cfd3ee957943f63d6152ed"
|
680
|
+
token = "176b9aba6b81256b50abf08526cf311a"
|
681
|
+
token = "7fdb556cbd1d01ba3e4a64eb0203d49d"
|
682
|
+
image_url = "https://oss.ffire.cc/files/kling_watermark.png"
|
683
|
+
|
684
|
+
# request = ImageRequest(prompt="做一个圣诞节的海报", size="1024x1024")
|
685
|
+
# request = ImageRequest(prompt="https://oss.ffire.cc/files/kling_watermark.png 让她带上墨镜", size="1024x1024")
|
686
|
+
|
687
|
+
# task = arun(create_task(request))
|
688
|
+
|
689
|
+
# task_id = "10040025470722"
|
690
|
+
|
691
|
+
# task_id = "10053536381698"
|
692
|
+
|
693
|
+
# task_id = "10079694738434"
|
694
|
+
|
695
|
+
# task_id = "10080831230210" # 图片编辑
|
696
|
+
|
697
|
+
# task_id = "10082971040514"
|
698
|
+
#
|
699
|
+
# arun(get_task(task_id, token))
|
700
|
+
|
701
|
+
# arun(get_task(task.task_id, task.system_fingerprint))
|
702
|
+
|
703
|
+
# task_id = "10184295086338"
|
704
|
+
# system_fingerprint = "eb4d120829cfd3ee957943f63d6152ed"
|
705
|
+
#
|
706
|
+
# t1 = ("10184295086338", "eb4d120829cfd3ee957943f63d6152ed")
|
707
|
+
# t2 = ("10184877310722", "dcf7bbc31faed9740b0bf748cd4d2c74")
|
708
|
+
# t3 = ("10186352959490", "eb4d120829cfd3ee957943f63d6152ed")
|
709
|
+
#
|
710
|
+
# arun(get_task(*t3))
|
711
|
+
|
712
|
+
from meutils.apis.jimeng.files import face_recognize
|
713
|
+
|
714
|
+
# face_recognize = arun(face_recognize(image_url, token))
|
715
|
+
#
|
716
|
+
# face_recognize_data = face_recognize.get("data", {})
|
717
|
+
|
718
|
+
# arun(generate(ImageRequest(**data)))
|
719
|
+
|
720
|
+
# arun(generate(ImageRequest(prompt="fuck you")))
|
721
|
+
# 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"
|
722
|
+
prompt = " a dog cat in the same room "
|
723
|
+
# prompt = "https://oss.ffire.cc/files/kling_watermark.png 让这个女人带上墨镜,衣服换个颜色... ! "
|
724
|
+
request = ImageRequest(prompt=prompt, size="1328x1328")
|
725
|
+
# request = ImageRequest(prompt=prompt, size="1024x1024")
|
726
|
+
|
727
|
+
# request = ImageRequest(prompt=prompt, size="2048*2048")
|
728
|
+
|
729
|
+
task = arun(create_task(request, token))
|
730
|
+
# task = arun(create_task(request, "d2d142fc877e696484cc2fc521127b36"))
|
731
|
+
# task = arun(create_task(request, "d2d142fc877e696484cc2fc521127b36"))
|
732
|
+
|
733
|
+
# arun(get_task(task.task_id, task.system_fingerprint))
|
734
|
+
# arun(get_task_plus(task.task_id, task.system_fingerprint))
|
735
|
+
# arun(get_task('16279716197378', 'd2d142fc877e696484cc2fc521127b36'))
|
736
|
+
# arun(get_task_plus('16279716197378', 'd2d142fc877e696484cc2fc521127b36'))
|
737
|
+
|
738
|
+
# TaskResponse(task_id='16127190069506', code=0, message=None, status='SUBMITTED', data=None,
|
739
|
+
# system_fingerprint='8089661372fe8db9795cc507c3049625', model=None,
|
740
|
+
# created_at='2025-05-06T19:49:50.933089')
|
741
|
+
|
742
|
+
# arun(get_task("47185525857809", token))
|
743
|
+
|
744
|
+
# arun(generate(request))
|