| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import logging
- from setting import ollama_client
- logger = logging.getLogger(__name__)
- model_name = 'moondream'
- def describe_frame(scene_list):
- results = []
- logger.info(f"🚀 开始分析视频,共有 {len(scene_list)} 个场景待处理...")
- for i, scene in enumerate(scene_list):
- logger.info(f"\n🎬 正在处理场景 {i + 1}/{len(scene_list)} (时间点: {scene['frame_pos']}s)")
- frame_path = scene['frame_path']
- with open(frame_path, 'rb') as f:
- image_bytes = f.read()
- image_data = {
- "scene_start": scene['scene_start'],
- "scene_end": scene['scene_end'],
- "frame_pos": scene['frame_pos'],
- "frame_path": frame_path,
- "prompts": []
- }
- prompts = [
- """
- Analyze the physical interaction between the individuals. Is there any intimate or sexual contact visible? Describe the positioning of their bodies and limbs objectively
- """,
- """
- Describe the clothing status of all individuals. Is there any visible nudity, undergarments, or partially exposed sensitive areas? Identify the specific body parts shown.
- """,
- """
- Observe the posture and movement. Does the scene depict a sexual act or a highly suggestive sexual position?provide a neutral description of the pose.
- """
- ]
- for i, p in enumerate(prompts):
- try:
- response = ollama_client.chat(
- model=model_name,
- messages=[{
- 'role': 'user',
- 'content': p,
- 'images': [image_bytes]
- }]
- )
- eng_text = response['message']['content']
- eng_text1 = eng_text.strip()
- prompt_item = {
- "prompt": p,
- "result": eng_text1
- }
- image_data["prompts"].append(prompt_item)
- except Exception as e:
- logger.error(f"❌ Prompt {i + 1} 推理失败: {e}")
- results.append(image_data)
- return results
- def describe_image(prompts, image_bytes):
- results = []
- for i, p in enumerate(prompts):
- response = ollama_client.chat(
- model=model_name,
- messages=[{
- 'role': 'user',
- 'content': p,
- 'images': [image_bytes]
- }]
- )
- eng_text = response['message']['content']
- prompt_item = {
- "prompt": p,
- "result": eng_text.strip()
- }
- results.append(prompt_item)
- return {
- "model_name": model_name,
- "results": results
- }
|