|
@@ -13,6 +13,7 @@ from whisper_asr import get_whisper_asr
|
|
|
from gpt_tag import request_gpt
|
|
|
from config import set_config
|
|
|
from log import Log
|
|
|
+import mysql_connect
|
|
|
config_ = set_config()
|
|
|
log_ = Log()
|
|
|
features = ['videoid', 'title', 'video_path']
|
|
@@ -57,31 +58,28 @@ def get_video_ai_tags(video_id, asr_file, video_info):
|
|
|
keywords = gpt_res1_json['keywords']
|
|
|
log_message['summary'] = summary
|
|
|
log_message['keywords'] = str(keywords)
|
|
|
+
|
|
|
+ # TODO 三个 prompt 拆分成三个请求
|
|
|
prompt2_param = f"标题:{title}\n概况:{summary}\n关键词:{keywords}"
|
|
|
- prompt2 = f"{config_.GPT_PROMPT['tags']['prompt7']}{prompt2_param}"
|
|
|
- log_message['gptPromptTag'] = prompt2
|
|
|
+ prompt2 = f"{config_.GPT_PROMPT['tags']['prompt8']}{prompt2_param}"
|
|
|
+ log_message['gptPrompt2'] = prompt2
|
|
|
gpt_res2 = request_gpt(prompt=prompt2)
|
|
|
- log_message['gptResTag'] = gpt_res2
|
|
|
+ log_message['gptRes2'] = gpt_res2
|
|
|
+ prompt3 = f"{config_.GPT_PROMPT['tags']['prompt9']}{prompt2_param}"
|
|
|
+ log_message['gptPrompt3'] = prompt3
|
|
|
+ gpt_res3 = request_gpt(prompt=prompt3)
|
|
|
+ log_message['gptRes3'] = gpt_res3
|
|
|
+ prompt4 = f"{config_.GPT_PROMPT['tags']['prompt10']}{prompt2_param}"
|
|
|
+ log_message['gptPrompt4'] = prompt4
|
|
|
+ gpt_res4 = request_gpt(prompt=prompt4)
|
|
|
+ log_message['gptRes4'] = gpt_res4
|
|
|
+ # 5. 解析gpt产出结果
|
|
|
+ parseRes = praseGptRes(gpt_res2, gpt_res3, gpt_res4)
|
|
|
+ log_message.update(parseRes)
|
|
|
+
|
|
|
+ # 6. 保存结果
|
|
|
+ mysql_connect.insert_content()
|
|
|
|
|
|
- if gpt_res2 is not None:
|
|
|
- confidence_up_list = []
|
|
|
- try:
|
|
|
- for item in json.loads(gpt_res2):
|
|
|
- if item['confidence'] > 0.5 and item['category'] in config_.TAGS_NEW:
|
|
|
- confidence_up_list.append(
|
|
|
- f"AI标签-{item['category']}")
|
|
|
- except:
|
|
|
- pass
|
|
|
- confidence_up = ','.join(confidence_up_list)
|
|
|
- log_message['AITags'] = confidence_up
|
|
|
- # 5. 调用后端接口,结果传给后端
|
|
|
- if len(confidence_up) > 0:
|
|
|
- response = requests.post(url=config_.ADD_VIDEO_AI_TAGS_URL,
|
|
|
- json={'videoId': int(video_id), 'tagNames': confidence_up})
|
|
|
- res_data = json.loads(response.text)
|
|
|
- if res_data['code'] != 0:
|
|
|
- log_.error(
|
|
|
- {'videoId': video_id, 'msg': 'add video ai tags fail!'})
|
|
|
except:
|
|
|
pass
|
|
|
else:
|
|
@@ -93,6 +91,36 @@ def get_video_ai_tags(video_id, asr_file, video_info):
|
|
|
log_.error(traceback.format_exc())
|
|
|
|
|
|
|
|
|
+def praseGptRes(gpt_res2, gpt_res3, gpt_res4):
|
|
|
+ result = {}
|
|
|
+ if gpt_res2 is not None:
|
|
|
+ try:
|
|
|
+ res2 = json.loads(gpt_res2)
|
|
|
+ result['key_words'] = res2['key_words']
|
|
|
+ result['search_keys'] = res2['search_keys']
|
|
|
+ result['extra_keys'] = res2['extra_keys']
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+ if gpt_res3 is not None:
|
|
|
+ try:
|
|
|
+ res3 = json.loads(gpt_res3)
|
|
|
+ result['tone'] = res3['tone']
|
|
|
+ result['target_audience'] = res3['target_audience']
|
|
|
+ result['target_age'] = res3['target_age']
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+ if gpt_res4 is not None:
|
|
|
+ try:
|
|
|
+ res4 = json.loads(gpt_res4)
|
|
|
+ result['category'] = res4['category']
|
|
|
+ result['target_gender'] = res4['target_gender']
|
|
|
+ result['address'] = res4['address']
|
|
|
+ result['theme'] = res4['theme']
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+ return result
|
|
|
+
|
|
|
+
|
|
|
def process(video_id, video_info, download_folder):
|
|
|
if video_info.get(video_id, None) is None:
|
|
|
shutil.rmtree(os.path.join(download_folder, video_id))
|
|
@@ -238,7 +266,7 @@ def timer_check():
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
# timer_check()
|
|
|
- size = 1000
|
|
|
+ size = 10000
|
|
|
for i in range(0, 2000, size):
|
|
|
print(f"query_videos start i = {i} ...")
|
|
|
records = ODPSQueryUtil.query_videos(i, size)
|
|
@@ -280,3 +308,7 @@ if __name__ == '__main__':
|
|
|
get_video_ai_tags(
|
|
|
video_id=video_id, asr_file=asr_file, video_info=video_info.get(video_id))
|
|
|
os.remove(asr_file)
|
|
|
+
|
|
|
+
|
|
|
+# get_video_ai_tags(16598277, 'aigc-test/asr_res/16598277.txt',
|
|
|
+# {'title': '九九重阳节送祝福🚩', 'video_path': '视频路径'})
|