zhangyong 5 maanden geleden
bovenliggende
commit
c09dfca6d6
1 gewijzigde bestanden met toevoegingen van 16 en 2 verwijderingen
  1. 16 2
      job.py

+ 16 - 2
job.py

@@ -159,7 +159,7 @@ def analyze_video(model: genai.GenerativeModel, google_file: File, prompt: str,
             content = {
                 'parts': [
                     google_file,
-                    f'{prompt}\n标题理解:请对"{title}"进行分析概括3~5个词[]":\n输出返回格式样例:\n{SAMPLE_DATA}',
+                    f'{prompt}\n九、标题理解:请对"{title}"标题进行分析概括3~5个词[]":\n输出返回格式样例:\n{SAMPLE_DATA}',
                 ],
             }
             return session.send_message(content=content)
@@ -205,6 +205,9 @@ def run():
         AliyunLogger.logging( str( redis_task['video_id'] ), redis_task['title'], redis_task['video_path'], "",
                               redis_task['type'], redis_task['partition'], "[+] 视频下载失败, 跳过任务" )
         logger.error(f'[+] 视频下载失败, 跳过任务')
+        if os.path.exists(video_path):
+            os.remove(video_path)
+            logger.info(f"文件已删除: {video_path}")
         return
 
     google_file, google_file_state = upload_video(video_path=video_path, redis_task=redis_task)
@@ -213,25 +216,36 @@ def run():
     elif google_file_state != 'ACTIVE':
         logger.error('[+] 视频上传状态不为 ACTIVE, 跳过任务')
         genai.delete_file(google_file)
+        if os.path.exists(video_path):
+            os.remove(video_path)
+            logger.info(f"文件已删除: {video_path}")
         return
 
     model = create_model_cache(redis_task=redis_task)
     if isinstance(model, str):
         logger.error('[+] 创建模型失败, 跳过任务')
         genai.delete_file(google_file)
+        if os.path.exists(video_path):
+            os.remove(video_path)
+            logger.info(f"文件已删除: {video_path}")
         return
 
     response = analyze_video(model=model, google_file=google_file, prompt=prompt, redis_task=redis_task, title=redis_task['title'])
     if isinstance(response, str):
         logger.error('[+] 获取模型响应失败, 跳过任务')
         genai.delete_file(google_file)
+        if os.path.exists(video_path):
+            os.remove(video_path)
+            logger.info(f"文件已删除: {video_path}")
         return
 
     text = response.text.strip()
     cleaned_text = text.replace("```json", '').replace("```", '').strip()
     AliyunLogger.logging( str(redis_task['video_id']), redis_task['title'], redis_task['video_path'], str(mark), redis_task['type'], redis_task['partition'], str(cleaned_text))
     logger.info(f'[+] 模型响应结果: {text}')
-
+    if os.path.exists(video_path):
+        os.remove(video_path)
+        logger.info(f"文件已删除: {video_path}")
     genai.delete_file(google_file)