Spaces:
Runtime error
Runtime error
Update gen_client.py
Browse files- gen_client.py +15 -27
gen_client.py
CHANGED
|
@@ -74,31 +74,6 @@ def sync_request_local(request_id, data):
|
|
| 74 |
print(f"request_id: {request_id}, request type: video generation, retuen message: Faild, result: {result_video_url}")
|
| 75 |
return result_video_url
|
| 76 |
|
| 77 |
-
def sync_request_cartoon(request_id, data):
|
| 78 |
-
headers = {
|
| 79 |
-
"Content-Type": "application/json",
|
| 80 |
-
"Accept": "application/json",
|
| 81 |
-
"Authorization": EAS_AUTH_CARTOONRECOG,
|
| 82 |
-
# "X-DashScope-Async": "enable",
|
| 83 |
-
# "X-DashScope-DataInspection": "enable"
|
| 84 |
-
}
|
| 85 |
-
url_create_task = 'http://1096433202046721.cn-shanghai.pai-eas.aliyuncs.com/api/predict/videogene_supp/api'
|
| 86 |
-
|
| 87 |
-
print(f"request_id: {request_id}, request type: cartoon recognize, json input: {data}")
|
| 88 |
-
res_ = requests.post(url_create_task, data=data, headers=headers)
|
| 89 |
-
# print(res_)
|
| 90 |
-
# print(res_.content)
|
| 91 |
-
res = json.loads(res_.content.decode())
|
| 92 |
-
|
| 93 |
-
cartoon_recog = ''
|
| 94 |
-
if res['payload']['output']['error_message'] == 'Success':
|
| 95 |
-
cartoon_recog = res['payload']['output']['key']['label']
|
| 96 |
-
# print(f"request_id: {request_id} cartoon_recog: {cartoon_recog}")
|
| 97 |
-
print(f"request_id: {request_id}, request type: cartoon recognize, retuen message: Succees, result: {cartoon_recog}")
|
| 98 |
-
else:
|
| 99 |
-
print(f"request_id: {request_id}, request type: cartoon recognize, retuen message: Faild, result: {cartoon_recog}")
|
| 100 |
-
return cartoon_recog
|
| 101 |
-
|
| 102 |
def sync_request_translate_en2cn(request_id, data):
|
| 103 |
headers = {
|
| 104 |
"Content-Type": "application/json",
|
|
@@ -355,6 +330,20 @@ class HumanGenService:
|
|
| 355 |
#--------------- translate service -----------------#
|
| 356 |
print(f'[{request_id}] - [HumanGen] - translate ok')
|
| 357 |
return translate_cn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
|
| 359 |
|
| 360 |
def click_button_prompt(self, user_id, request_id, input_mode, ref_image_path, ref_video_path, input_prompt='', prompt_template='',model_id=False):
|
|
@@ -425,8 +414,7 @@ class HumanGenService:
|
|
| 425 |
prompt_caption_data['payload'] = {}
|
| 426 |
prompt_caption_data['payload']['input'] = {}
|
| 427 |
prompt_caption_data['payload']['input']['work_type'] = 'prompt_caption'
|
| 428 |
-
|
| 429 |
-
sign_vid_oss_path = oss_endpoint_seg + '-internal' + sign_vid_oss_path[len(oss_endpoint_seg):]
|
| 430 |
print(f"request_id: {request_id}, video internal oss path for caption: {sign_vid_oss_path}")
|
| 431 |
prompt_caption_data['payload']['input']['key'] = sign_vid_oss_path
|
| 432 |
prompt_caption_data['payload']['parameters'] = {}
|
|
|
|
| 74 |
print(f"request_id: {request_id}, request type: video generation, retuen message: Faild, result: {result_video_url}")
|
| 75 |
return result_video_url
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
def sync_request_translate_en2cn(request_id, data):
|
| 78 |
headers = {
|
| 79 |
"Content-Type": "application/json",
|
|
|
|
| 330 |
#--------------- translate service -----------------#
|
| 331 |
print(f'[{request_id}] - [HumanGen] - translate ok')
|
| 332 |
return translate_cn
|
| 333 |
+
|
| 334 |
+
def signed_oss_path_to_internal(self, signed_oss_path):
|
| 335 |
+
sign_internal_oss_path = ''
|
| 336 |
+
import re
|
| 337 |
+
pattern = r"http.*\.aliyuncs.com"
|
| 338 |
+
match = re.search(pattern, signed_oss_path)
|
| 339 |
+
if match:
|
| 340 |
+
oss_address0 = match.group()
|
| 341 |
+
oss_address1 = signed_oss_path[len(oss_address0):]
|
| 342 |
+
oss_endpoint_seg = oss_address0[:-len(".aliyuncs.com")]
|
| 343 |
+
sign_internal_oss_path = oss_endpoint_seg + '-internal.aliyuncs.com' + oss_address1
|
| 344 |
+
else:
|
| 345 |
+
print(f'[{request_id}] - [HumanGen] - signed_oss_path_to_internal faild for {signed_oss_path}')
|
| 346 |
+
return sign_internal_oss_path
|
| 347 |
|
| 348 |
|
| 349 |
def click_button_prompt(self, user_id, request_id, input_mode, ref_image_path, ref_video_path, input_prompt='', prompt_template='',model_id=False):
|
|
|
|
| 414 |
prompt_caption_data['payload'] = {}
|
| 415 |
prompt_caption_data['payload']['input'] = {}
|
| 416 |
prompt_caption_data['payload']['input']['work_type'] = 'prompt_caption'
|
| 417 |
+
sign_vid_oss_path = self.signed_oss_path_to_internal(sign_vid_oss_path)
|
|
|
|
| 418 |
print(f"request_id: {request_id}, video internal oss path for caption: {sign_vid_oss_path}")
|
| 419 |
prompt_caption_data['payload']['input']['key'] = sign_vid_oss_path
|
| 420 |
prompt_caption_data['payload']['parameters'] = {}
|