blip / src /labeler.py
amezi's picture
debugging togetherai
aa822ad
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:
This is a football game in seria A between Juventus and Empoli. Juventus is dressed in Dark Navy kit and the keeper is in orange, Empoli, the away team is dressed in white jersey and the keeper in fluorescent yellow. The referee is dressed in a red shirt and black shorts. The home team is Juventus-- the game is being played at the Allianz stadium.
Commentary:
{transcript}
Instructions:
- Summarize this event in factual soccer terminology.
- Focus on the play's significance to the score.
- Avoid exaggeration.
"""
prompt = "hi how you doin"
#images = [{"type": "image_url", "image_url": {"url": url}} for url in frame_urls]
images = [{"type": "image_url", "image_url": {"url": frame_urls[1]}}]
#content = [{"type": "text", "text": prompt}] + images
content = [{"type": "text", "text": prompt}]
messagez=[{"role": "user", "content": content}]
print (messagez)
response = self.client.chat.completions.create(
model="meta-llama/Llama-Vision-Free",
messages=[{"role": "user", "content": content}],
#max_tokens=200
)
# messages=[{"role": "user", "content": content}],
print(response.choices[0].message.content)
#return response.choices[0].message["content"].strip()
return response.choices[0].message.content
#before commentary:
# Game Information:
# {game_card}
#after commentary:
# Spatial Context (object detections per frame):
# {spatial_context}