MCPcopy Create free account
hub / github.com/FunAudioLLM/MME-Emotion / process_entry

Function process_entry

extract_step/SA/code/extract_step.py:8–61  ·  view source on GitHub ↗
(model, client, entry)

Source from the content-addressed store, hash-verified

6from tqdm import tqdm
7
8def process_entry(model, client, entry):
9 messages = [
10 {
11 "role": "system",
12 "content": "You are an expert in affective computing and very good at handling tasks related to emotion recognition."
13 },
14 {
15 "role": "user",
16 "content": f"Given the following answer about the sentiment conveyed in a video, "
17 f"please help me extract several key steps from the answer. Each step should be as concise as "
18 f"possible and prefixed with Step X. In the last step, showcase the predicted sentiment. If there "
19 f"are no reasoning steps, please showcase the predicted sentiment at Step 1. Enclose your result "
20 f"within <step></step> tags.\n"
21 f"answer: '{entry['model_response']}'\n"
22 f"Example 1:\n"
23 f"answer: In the video, an elderly man wearing a green shirt is in an outdoor nighttime setting. He appears focused and serious, with slightly "
24 f"furrowed brows and a serious expression. His eyes are scanning the other person, suggesting he wants to convey something important or ask about "
25 f"a certain thing. As time passes, his gaze shifts from scanning to direct engagement, eventually relaxing and showing a hint of happiness, "
26 f"indicating fluctuations in his emotions. Overall, the elderly man experiences a moderate intensity of neutral sentiment, mixed with slight "
27 f"positive fluctuations.\n"
28 f"result: <step>Step 1: Observe the setting and characters in the video, noting any relevant details such as location and participants' appearance. "
29 f"Step 2: Analyze the facial expressions and movements, such as furrowed brows and downturned eyes, looking for indicators of specific emotions. "
30 f"Step 3: Consider verbal and non-verbal cues, including mouth movements and gaze direction, that signify communication and emotional responses. "
31 f"Step 4: Synthesize observations to understand the overall emotional state conveyed by the participant. "
32 f"Step 5: Based on the analysis, determine that the predicted sentiment is neutral.</step>\n"
33 f"Example 2:\n"
34 f"answer: positive\n"
35 f"result: <step>Step 1: The predicted sentiment is positive.</step>"
36 f"Example 3:\n"
37 f"answer: I cannot provide details about the video frames or the emotions displayed by the person in the video.\n"
38 f"result: <step>Step 1: The predicted sentiment is None.</step>"
39 }
40 ]
41
42 max_retries = 10
43 for attempt in range(max_retries):
44 try:
45 response = client.chat.completions.create(
46 model=model,
47 messages=messages,
48 temperature=0.0,
49 timeout=120
50 )
51 result = response.choices[0].message.content
52 entry['step'] = result
53 return True
54
55 except Exception as e:
56 if attempt < max_retries - 1:
57 time.sleep(2)
58 else:
59 entry['step'] = f"Error: {str(e)}"
60 return False
61 return False
62
63def process_json_file(input_file, output_file, model_name, api_key, base_url):
64

Callers 1

process_json_fileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected