|
|
@@ -53,11 +53,11 @@ class Glm:
|
|
|
|
|
|
return response.choices[0].message
|
|
|
|
|
|
- def multi_epoch_image_response(self, logo_path):
|
|
|
+ def multi_epoch_image_response(self, logo_path, image_url, query):
|
|
|
"""多轮图像问答"""
|
|
|
image_base = image_to_base(logo_path)
|
|
|
response = self.client.chat.completions.create(
|
|
|
- model="glm-4v-plus-0111",
|
|
|
+ model=self.model_name,
|
|
|
messages=[
|
|
|
{
|
|
|
"content": [
|
|
|
@@ -75,17 +75,20 @@ class Glm:
|
|
|
{
|
|
|
"content": [
|
|
|
{
|
|
|
- "image_url": {"url": "http://h2.appsimg.com/a.appsimg.com/upload/merchandise/pdcvis/2023/04/14/79/d75fa3db-3bec-45c4-b7a6-54332d42e373.jpg"},
|
|
|
+ "image_url": {"url": image_url},
|
|
|
"type": "image_url"
|
|
|
},
|
|
|
{
|
|
|
- "text": "第二张图像中的产品是否包含logo,如果包含的话是否是第一张的logo?",
|
|
|
+ "text": query,
|
|
|
"type": "text"
|
|
|
}
|
|
|
],
|
|
|
"role": "user"
|
|
|
}
|
|
|
- ]
|
|
|
+ ],
|
|
|
+ response_format = {
|
|
|
+ "type": "joson_object"
|
|
|
+ }
|
|
|
)
|
|
|
|
|
|
return response.choices[0].message
|
|
|
@@ -95,5 +98,26 @@ class Glm:
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
glm = Glm()
|
|
|
- response = glm.multi_epoch_image_response("./logo/lining.jpg")
|
|
|
- print(response)
|
|
|
+ glm.set_modelname("glm-4v-plus-0111")
|
|
|
+ query = f"""
|
|
|
+ 你是一个产品图像分析助手,你的任务是判断第二张图像中的产品上是否包含logo,并与第一张logo图像做对比,判断第二张图像中的logo是否与第一张的一致。
|
|
|
+ 判断思路:
|
|
|
+ 1. 首先判断第二张图像中是否包含logo。
|
|
|
+ 2. 如果包含logo的话,再进行判断,是否与第一张的logo一致。
|
|
|
+ 3. 如果与第一张的logo不一致,请根据你的经验判断图像中的logo是什么品牌,如果不知道返回'未知'
|
|
|
+ 最终结果返回为以下给出的json格式
|
|
|
+ 输出结果示例:
|
|
|
+
|
|
|
+ {{
|
|
|
+ "is_contain_logo": false
|
|
|
+ }}
|
|
|
+
|
|
|
+
|
|
|
+ {{
|
|
|
+ "is_contain_logo": true,
|
|
|
+ "is_jugement_logo": true,
|
|
|
+ "brand_name": "李宁"
|
|
|
+ }}
|
|
|
+ """
|
|
|
+ response = glm.multi_epoch_image_response("./logo/lining.jpg", "http://h2.appsimg.com/a.appsimg.com/upload/merchandise/pdcvis/613214/2024/1120/88/9b9027dd-95b7-4024-b71e-fb7cbfde16a1.jpg", query)
|
|
|
+ print(response.content)
|