Skip to content

Commit 0dfacbf

Browse files
committed
Fix import
1 parent 7d576f0 commit 0dfacbf

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

app/backend/prepdocslib/mediadescriber.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import base64
12
import logging
23
from abc import ABC
3-
import base64
44

55
import aiohttp
66
from azure.core.credentials_async import AsyncTokenCredential
77
from azure.identity.aio import get_bearer_token_provider
8+
from openai import AsyncOpenAI
89
from rich.progress import Progress
910
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed
10-
from openai import AsyncOpenAI
1111

1212
logger = logging.getLogger("scripts")
1313

@@ -107,12 +107,13 @@ async def describe_image(self, image_bytes: bytes) -> str:
107107
fields = results["result"]["contents"][0]["fields"]
108108
return fields["Description"]["valueString"]
109109

110+
110111
class MultimodalModelDescriber(MediaDescriber):
111112
def __init__(self, openai_client: AsyncOpenAI, model: str, deployment: str):
112113
self.openai_client = openai_client
113114
self.model = model
114115
self.deployment = deployment
115-
116+
116117
async def describe_image(self, image_bytes: bytes) -> str:
117118
image_base64 = base64.b64encode(image_bytes).decode("utf-8")
118119
image_datauri = f"data:image/png;base64,{image_base64}"
@@ -127,11 +128,15 @@ async def describe_image(self, image_bytes: bytes) -> str:
127128
},
128129
{
129130
"role": "user",
130-
"content":
131-
[{"text": "Describe image with no more than 5 sentences. Do not speculate about anything you don't know.", "type": "text"},
132-
{"image_url": {"url": image_datauri}, "type": "image_url", "detail": "auto"}]
133-
}
134-
])
131+
"content": [
132+
{
133+
"text": "Describe image with no more than 5 sentences. Do not speculate about anything you don't know.",
134+
"type": "text",
135+
},
136+
{"image_url": {"url": image_datauri}, "type": "image_url", "detail": "auto"},
137+
],
138+
},
139+
],
140+
)
135141
description = response.choices[0].message.content.strip() if response.choices else ""
136142
return description
137-

0 commit comments

Comments
 (0)