liqian 2 years ago
parent
commit
4c96e856cf
2 changed files with 32 additions and 23 deletions
  1. 26 17
      app.py
  2. 6 6
      gpt_process.py

+ 26 - 17
app.py

@@ -77,6 +77,8 @@ def title_generate_main():
                     # ppp = {'videoId': video_id, 'videoPath': video_path}
                     # log_.info(f"debug: {ppp}")
                     title = title_generate(video_id=video_id, video_path=video_path)
+                    if title[0] in ['"', "'"] and title[-1] in ['"', "'"]:
+                        title = title[1:-1]
                     log_.info({'titleGenerate': {'videoId': video_id, 'title': title}})
 
                 except ConnectionResetError:
@@ -134,7 +136,7 @@ def title_generate_main():
 
             # msg.next_consume_time前若不确认消息消费成功,则消息会被重复消费。
             # 消息句柄有时间戳,同一条消息每次消费拿到的都不一样。
-            log_.info(f"receipt_handle_list: {receipt_handle_list}")
+            # log_.info(f"receipt_handle_list: {receipt_handle_list}")
             consumer.ack_message(receipt_handle_list)
             log_.info({
                 'ackMessage': {
@@ -142,29 +144,36 @@ def title_generate_main():
                     'receiptHandleList': receipt_handle_list
                 }
             })
-        except MQExceptionBase as consume_e:
+        # except MQExceptionBase as consume_e:
+        #     log_.error({
+        #         'errorType': 'consume',
+        #         'status': 'fail',
+        #         'exception': consume_e,
+        #         'traceback': traceback.format_exc()
+        #     })
+        #     # Topic中没有消息可消费。
+        #     if consume_e.type == "MessageNotExist":
+        #         print(("No new message! RequestId: %s" % consume_e.req_id))
+        #         continue
+        #     # 某些消息的句柄可能超时,会导致消息消费状态确认不成功。
+        #     elif consume_e.sub_errors:
+        #         for sub_error in consume_e.sub_errors:
+        #             print(("\tErrorHandle:%s,ErrorCode:%s,ErrorMsg:%s" % \
+        #                    (sub_error["ReceiptHandle"], sub_error["ErrorCode"], sub_error["ErrorMessage"])))
+        #
+        #     log_.error("Consume Message Fail! Exception:%s\n" % consume_e)
+        #     time.sleep(30)
+        #     continue
+
+        except Exception as consume_e:
             log_.error({
                 'errorType': 'consume',
                 'status': 'fail',
                 'exception': consume_e,
                 'traceback': traceback.format_exc()
             })
-            # Topic中没有消息可消费。
-            if consume_e.type == "MessageNotExist":
-                print(("No new message! RequestId: %s" % consume_e.req_id))
-                continue
-            # 某些消息的句柄可能超时,会导致消息消费状态确认不成功。
-            elif consume_e.sub_errors:
-                for sub_error in consume_e.sub_errors:
-                    print(("\tErrorHandle:%s,ErrorCode:%s,ErrorMsg:%s" % \
-                           (sub_error["ReceiptHandle"], sub_error["ErrorCode"], sub_error["ErrorMessage"])))
-
-            log_.error("Consume Message Fail! Exception:%s\n" % consume_e)
-            time.sleep(2)
-            continue
-
-        except Exception as e:
             log_.error("Consume Message Fail! Exception:%s\n" % e)
+            time.sleep(30)
             continue
 
 

+ 6 - 6
gpt_process.py

@@ -51,21 +51,21 @@ def title_generate(video_id, video_path):
     :return:
     """
     # 1. 下载视频
-    log_.info(f"debug: title_generate 1")
+    # log_.info(f"debug: title_generate 1")
     video_file_path = download_video(video_path=video_path, video_id=video_id, download_folder='videos')
-    log_.info(f"video_file_path = {video_file_path}")
+    log_.info({'videoId': video_id, 'video_file_path': video_file_path})
     # 2. 获取视频中的音频
-    log_.info(f"debug: title_generate 2")
+    # log_.info(f"debug: title_generate 2")
     audio_path = get_wav(video_path=video_file_path)
-    log_.info(f"audio_path = {audio_path}")
+    log_.info({'videoId': video_id, 'audio_path': audio_path})
     # 3. asr
-    log_.info(f"debug: title_generate 3")
+    # log_.info(f"debug: title_generate 3")
     dialogue_path, asr_res = call_asr(audio_path=audio_path)
     log_.info({
         'asrResult': {'videoId': video_id, 'asrRes': asr_res}
     })
     # 4. gpt产出结果
-    log_.info(f"debug: title_generate 4")
+    # log_.info(f"debug: title_generate 4")
     prompt = f"{config_.GPT_PROMPT['title']['prompt2']}{asr_res.strip()}"
     gpt_res = request_gpt(prompt=prompt)
     # 5. 删除相关文件