blip / src /labeler.py
amezi's picture
minor bux fixed
87f3303
raw
history blame
1.11 kB
import os
from together import Together
from dotenv import load_dotenv
load_dotenv()
class TogetherLLMLabeler:
def __init__(self):
self.client = Together(api_key=os.getenv("TOGETHER_API_KEY"))
def generate_label(self, game_card, transcript, spatial_context, frame_urls):
prompt = f"""
Game Information:
{game_card}
Commentary:
{transcript}
Spatial Context (object detections per frame):
{spatial_context}
Instructions:
- Summarize this event in factual soccer terminology.
- Focus on the play's significance to the score.
- Avoid exaggeration.
"""
images = [{"type": "image_url", "image_url": {"url": url}} for url in frame_urls]
content = [{"type": "text", "text": prompt}] + images
response = self.client.chat_completions.create(
model="meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo",
messages=[{"role": "user", "content": content}],
max_tokens=200
)
return response.choices[0].message["content"].strip()