zhangyong 6 月之前
父節點
當前提交
862e8eabdc
共有 1 個文件被更改,包括 40 次插入7 次删除
  1. 40 7
      google_ai/generativeai_video.py

+ 40 - 7
google_ai/generativeai_video.py

@@ -67,7 +67,7 @@ class VideoAnalyzer:
             "top_p": 0.95,
             "top_k": 64,
             "max_output_tokens": 8192,
-            "response_mime_type": "text/plain",
+            "response_mime_type": "application/json"
         }
         """创建缓存内容,并返回生成模型"""
         # 创建生成模型,使用 gemini-1.5-flash 模型
@@ -78,7 +78,7 @@ class VideoAnalyzer:
         )
 
         return model
-    async def analyze_video(self, model, questions):
+    async def analyze_video(self, model, questions, sample_data):
             chat_session = model.start_chat(
                 history=[
                 ]
@@ -86,7 +86,9 @@ class VideoAnalyzer:
             message_content = {
                 "parts": [
                     self.video_file,
-                    "你是一个专业的视频分析师,负责根据访问的视频文件回答用户的所有问题\\n"+questions
+                    "你是一个专业的视频分析师,负责根据访问的视频文件回答用户的所有问题\\n"+questions +
+                    "输出返回格式样例:\n"+ str(sample_data)
+
                 ]
             }
             response = chat_session.send_message( message_content )
@@ -111,9 +113,42 @@ async def main(video_path):
 
     # 创建缓存模型
     model =await analyzer.create_cache()
+    sample_data = {
+        "一、基础信息": {
+            "1.视觉/音乐/文字": "",
+            "2.内容选题": "",
+            "3.视频主题": ""
+        },
+        "二、主体和场景": {
+            "1.视频主体": "",
+            "2.视频场景": []
+        },
+        "三、情感与风格": {},
+        "四、视频传播性与观众": {
+            "1.片尾引导": {},
+            "2.传播性判断": "",
+            "3.观众画像": {}
+        },
+        "五、音画细节": {
+            "1.音频细节": {},
+            "2.视频水印": {},
+            "3.视频字幕": {},
+            "4.视频口播": ""
+        },
+        "六、人物与场景": {
+            "1.知名人物": {},
+            "2.人物年龄段": "",
+            "3.场景描述": []
+        },
+        "七、时效性与分类": {
+            "1.时效性": {},
+            "2.视频一级分类": "",
+            "3.二级分类": ""
+        }
+    }
 
     # 视频分析问题
-    video_analysis_questions = "一、基础信息:\n                    " \
+    video_analysis_questions = "一、基础信息:\n" \
                                "1.视觉/音乐/文字: 请从视频中的视觉、音乐、文字这三个维度信息做分析比较,哪个维度的信息是该视频中最重要的,可能成为该视频的要点驱动力?你只要回答 视觉/音乐/文字 三者其一即可。\n" \
                                "2.内容选题: 如果需要从视频中提取一个内容选题,你觉得应该是什么?请注意:选题应该体现视频的关键点,亮点,爆点,选题不能超过8个字。\n" \
                                "3.视频主题:描述视频的整体主题。\n " \
@@ -314,11 +349,9 @@ async def main(video_path):
                                "品类-国际军事\n" \
                                "品类-国内军事\n" \
                                "品类-国家统一\n" \
-                               "输出格式:要求输出格式为符合RFC8259标准的JSON格式的字符串"
-
 
     # 分析视频并打印结果
-    response =await analyzer.analyze_video( model, video_analysis_questions )
+    response =await analyzer.analyze_video( model, video_analysis_questions, sample_data )
     print( response.usage_metadata )
     print(response.text)
     if os.path.exists( save_path ):