import requests import json class CoverAnalyzer: @staticmethod def cover_list_data(cover_list): list_data = [] for cover in cover_list: data_dict = CoverAnalyzer.analyze_covers(cover) list_data.append(data_dict) return list_data @staticmethod def analyze_covers(cover): for i in range(3): url = "http://aigc-api.cybertogether.net//aigc/dev/test/gpt" payload = json.dumps({ "imageList": [cover], "prompt": "请帮我完成图片分析工作", "responseFormat": { "type": "json_schema", "json_schema": { "strict": True, "name": "comprehension_result", "schema": { "type": "object", "properties": { "是否包含老年人为画面主体": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否包含老年人为画面主体,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否有多人为画面主体": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否有多人为画面主体,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否有超过3人为画面主体": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否有超过3人为画面主体,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否充斥画面的密集人群为画面主体": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否充斥画面的密集人群为画面主体,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否存在知名历史、近代人物": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否存在知名历史、近代人物,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否存在人物脸部、头部未完整出现在画面的情况": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否存在人物脸部、头部未完整出现在画面的情况,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否是不以人为主体的鲜花、美景、知名建筑或风景": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否是不以人为主体的鲜花、美景、知名建筑或风景,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否是老照片、怀旧风格": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否是老照片、怀旧风格,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否是农村、军事、综艺演出、历史画面": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否是农村、军事、综艺演出、历史画面,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否有趣味、惊奇的形象或画面为主体": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否有趣味、惊奇的形象或画面为主体,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否以大号文字或密集文字为主体并且不包含人物": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否以大号文字或密集文字为主体并且不包含人物,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否是不包含人物的纯色画面": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否是不包含人物的纯色画面,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False }, "是否是模糊的或清晰度、像素较低的": { "type": "object", "properties": { "result": { "description": "请分析所有图片,是否是模糊的或清晰度、像素较低的,如果是返回1,如果不是返回0", "type": "number", "enum": [1, 0] }, "reason": { "description": "得出结论的客观的分析原因和依据", "type": "string" } }, "required": ["result", "reason"], "additionalProperties": False } }, "additionalProperties": False, "required": [ "是否包含老年人为画面主体", "是否有多人为画面主体", "是否有超过3人为画面主体", "是否充斥画面的密集人群为画面主体", "是否存在知名历史、近代人物", "是否存在人物脸部、头部未完整出现在画面的情况", "是否是不以人为主体的鲜花、美景、知名建筑或风景", "是否是老照片、怀旧风格", "是否是农村、军事、综艺演出、历史画面", "是否有趣味、惊奇的形象或画面为主体", "是否以大号文字或密集文字为主体并且不包含人物", "是否是不包含人物的纯色画面", "是否是模糊的或清晰度、像素较低的" ] } } } }) headers = {'Content-Type': 'application/json'} try: response = requests.post(url, headers=headers, data=payload) response_data = response.json() data = json.loads(response_data.get('data', '{}')) result_sum = sum(item['result'] for item in data.values()) # 获取总和 data_dict = { "data": str(data), "cover_url": cover, "cover_sum": result_sum } return data_dict except requests.exceptions.RequestException as e: print(f"请求出错: {e}") continue except json.JSONDecodeError as e: print(f"JSON 解析错误: {e}") continue except Exception as e: print(f"其他错误: {e}") continue return None