-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
Python codes here:
def download_image(src) -> BytesIO:
resp = req.get(src, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}, stream=True, timeout=10)
resp.raise_for_status()
img_data = BytesIO(resp.content)
img_data.seek(0)
return img_data
def caption_image(src, cache_dir):
model = lms.llm(config={"temperature": 0.1})
try:
img = download_image(src)
image_handle = lms.prepare_image(img)
chat = lms.Chat()
chat.add_user_message("Describe this image please ", images=[image_handle])
prediction = model.respond(chat)
return f""
except:
return f""repond random answer.
but save image to temp file and prepare_image(/path/to/temp.jpeg) works fine.
Metadata
Metadata
Assignees
Labels
No labels