Repository navigation
Expand file tree
/
Copy pathcheck_once.py
More file actions
58 lines (45 loc) · 1.54 KB
/
Copy pathcheck_once.py
File metadata and controls
58 lines (45 loc) · 1.54 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Trio API - Single Condition Check
This example shows how to perform a one-shot check on a YouTube Live stream.
The API analyzes a single frame and returns whether your condition is met.
Usage:
export TRIO_API_KEY="your_api_key"
python check_once.py
"""
import os
import requests
TRIO_API = "https://trio.machinefi.com/api"
API_KEY = os.environ.get("TRIO_API_KEY", "YOUR_API_KEY")
# Example: Check if there's an animated character on the lofi girl stream
STREAM_URL = "https://www.youtube.com/watch?v=jfKfPfyJRdk"
CONDITION = "Is there an animated character visible?"
def check_once(stream_url: str, condition: str) -> dict:
"""
Perform a single condition check on a live stream.
Args:
stream_url: YouTube Live URL to analyze
condition: Yes/no question about what to detect
Returns:
API response with triggered status and explanation
"""
response = requests.post(
f"{TRIO_API}/check-once",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
},
json={
"stream_url": stream_url,
"condition": condition
}
)
response.raise_for_status()
return response.json()
if __name__ == "__main__":
print(f"Checking: {CONDITION}")
print(f"Stream: {STREAM_URL}")
print()
result = check_once(STREAM_URL, CONDITION)
print(f"Triggered: {result['triggered']}")
print(f"Explanation: {result['explanation']}")
print(f"Latency: {result.get('latency_ms', 'N/A')}ms")