File size: 1,106 Bytes
58ac08a
 
87f3303
 
 
58ac08a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()