Spaces:
Runtime error
Runtime error
Update PCAgent/chat.py
Browse files- PCAgent/chat.py +29 -23
PCAgent/chat.py
CHANGED
|
@@ -34,28 +34,28 @@ def add_response_old(role, prompt, chat_history, image=None):
|
|
| 34 |
new_chat_history = copy.deepcopy(chat_history)
|
| 35 |
if image:
|
| 36 |
base64_image = resize_encode_image(image)
|
| 37 |
-
# content = [
|
| 38 |
-
# {
|
| 39 |
-
# "type": "text",
|
| 40 |
-
# "text": prompt
|
| 41 |
-
# },
|
| 42 |
-
# {
|
| 43 |
-
# "type": "image_url",
|
| 44 |
-
# "image_url": {
|
| 45 |
-
# "url": f"data:image/jpeg;base64,{base64_image}"
|
| 46 |
-
# }
|
| 47 |
-
# },
|
| 48 |
-
# ]
|
| 49 |
content = [
|
| 50 |
{
|
| 51 |
"type": "text",
|
| 52 |
"text": prompt
|
| 53 |
},
|
| 54 |
{
|
| 55 |
-
"type": "
|
| 56 |
-
"
|
|
|
|
|
|
|
| 57 |
},
|
| 58 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
content = [
|
| 61 |
{
|
|
@@ -76,11 +76,13 @@ def add_response(role, prompt, chat_history, image=[], use_qwen=False):
|
|
| 76 |
},
|
| 77 |
]
|
| 78 |
for i in range(len(image)):
|
| 79 |
-
|
| 80 |
content.append(
|
| 81 |
{
|
| 82 |
-
"type": "
|
| 83 |
-
"
|
|
|
|
|
|
|
| 84 |
}
|
| 85 |
)
|
| 86 |
new_chat_history.append([role, content])
|
|
@@ -90,20 +92,24 @@ def add_response(role, prompt, chat_history, image=[], use_qwen=False):
|
|
| 90 |
def add_response_two_image(role, prompt, chat_history, image):
|
| 91 |
new_chat_history = copy.deepcopy(chat_history)
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
content = [
|
| 96 |
{
|
| 97 |
"type": "text",
|
| 98 |
"text": prompt
|
| 99 |
},
|
| 100 |
{
|
| 101 |
-
"type": "
|
| 102 |
-
"
|
|
|
|
|
|
|
| 103 |
},
|
| 104 |
{
|
| 105 |
-
"type": "
|
| 106 |
-
"
|
|
|
|
|
|
|
| 107 |
}
|
| 108 |
]
|
| 109 |
|
|
|
|
| 34 |
new_chat_history = copy.deepcopy(chat_history)
|
| 35 |
if image:
|
| 36 |
base64_image = resize_encode_image(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
content = [
|
| 38 |
{
|
| 39 |
"type": "text",
|
| 40 |
"text": prompt
|
| 41 |
},
|
| 42 |
{
|
| 43 |
+
"type": "image_url",
|
| 44 |
+
"image_url": {
|
| 45 |
+
"url": f"data:image/jpeg;base64,{base64_image}"
|
| 46 |
+
}
|
| 47 |
},
|
| 48 |
]
|
| 49 |
+
# content = [
|
| 50 |
+
# {
|
| 51 |
+
# "type": "text",
|
| 52 |
+
# "text": prompt
|
| 53 |
+
# },
|
| 54 |
+
# {
|
| 55 |
+
# "type": "image",
|
| 56 |
+
# "image": f"file://{image}"
|
| 57 |
+
# },
|
| 58 |
+
# ]
|
| 59 |
else:
|
| 60 |
content = [
|
| 61 |
{
|
|
|
|
| 76 |
},
|
| 77 |
]
|
| 78 |
for i in range(len(image)):
|
| 79 |
+
base64_image = resize_encode_image(image[i])
|
| 80 |
content.append(
|
| 81 |
{
|
| 82 |
+
"type": "image_url",
|
| 83 |
+
"image_url": {
|
| 84 |
+
"url": f"data:image/jpeg;base64,{base64_image}"
|
| 85 |
+
}
|
| 86 |
}
|
| 87 |
)
|
| 88 |
new_chat_history.append([role, content])
|
|
|
|
| 92 |
def add_response_two_image(role, prompt, chat_history, image):
|
| 93 |
new_chat_history = copy.deepcopy(chat_history)
|
| 94 |
|
| 95 |
+
base64_image1 = resize_encode_image(image[0])
|
| 96 |
+
base64_image2 = resize_encode_image(image[1])
|
| 97 |
content = [
|
| 98 |
{
|
| 99 |
"type": "text",
|
| 100 |
"text": prompt
|
| 101 |
},
|
| 102 |
{
|
| 103 |
+
"type": "image_url",
|
| 104 |
+
"image_url": {
|
| 105 |
+
"url": f"data:image/jpeg;base64,{base64_image1}"
|
| 106 |
+
}
|
| 107 |
},
|
| 108 |
{
|
| 109 |
+
"type": "image_url",
|
| 110 |
+
"image_url": {
|
| 111 |
+
"url": f"data:image/jpeg;base64,{base64_image2}"
|
| 112 |
+
}
|
| 113 |
}
|
| 114 |
]
|
| 115 |
|