Spaces:
Paused
Paused
Changed how images is passed to local model
Browse files
app.py
CHANGED
|
@@ -98,27 +98,31 @@ def local_score(image_path, prompt, max_tokens, temperature, top_p) -> str:
|
|
| 98 |
dtype=dtype,
|
| 99 |
)
|
| 100 |
|
| 101 |
-
with Image.open(image_path) as uploaded_image:
|
| 102 |
-
image = uploaded_image.convert("RGB")
|
| 103 |
-
|
| 104 |
messages = [
|
| 105 |
{
|
| 106 |
"role": "user",
|
| 107 |
"content": [
|
| 108 |
-
{
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
],
|
| 111 |
}
|
| 112 |
]
|
|
|
|
| 113 |
output = local_pipe(
|
| 114 |
text=messages,
|
| 115 |
-
images=[image],
|
| 116 |
max_new_tokens=max_tokens,
|
| 117 |
do_sample=temperature > 0,
|
| 118 |
temperature=max(temperature, 0.01),
|
| 119 |
top_p=top_p,
|
| 120 |
return_full_text=False,
|
| 121 |
)
|
|
|
|
| 122 |
generated = output[0]["generated_text"]
|
| 123 |
if isinstance(generated, list):
|
| 124 |
generated = generated[-1].get("content", str(generated[-1]))
|
|
|
|
| 98 |
dtype=dtype,
|
| 99 |
)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
| 101 |
messages = [
|
| 102 |
{
|
| 103 |
"role": "user",
|
| 104 |
"content": [
|
| 105 |
+
{
|
| 106 |
+
"type": "image",
|
| 107 |
+
"path": image_path,
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"type": "text",
|
| 111 |
+
"text": prompt,
|
| 112 |
+
},
|
| 113 |
],
|
| 114 |
}
|
| 115 |
]
|
| 116 |
+
|
| 117 |
output = local_pipe(
|
| 118 |
text=messages,
|
|
|
|
| 119 |
max_new_tokens=max_tokens,
|
| 120 |
do_sample=temperature > 0,
|
| 121 |
temperature=max(temperature, 0.01),
|
| 122 |
top_p=top_p,
|
| 123 |
return_full_text=False,
|
| 124 |
)
|
| 125 |
+
|
| 126 |
generated = output[0]["generated_text"]
|
| 127 |
if isinstance(generated, list):
|
| 128 |
generated = generated[-1].get("content", str(generated[-1]))
|