File size: 1,197 Bytes
3d9c57d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# backend/utils/huggingface_api.py
import requests
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# HuggingFace API configuration
HF_API_URL = "https://api.huggingface.co/submit_match"  # Replace with actual endpoint
HF_API_TOKEN = os.getenv("HF_API_TOKEN")

def submit_to_huggingface(video_path: str) -> dict:
    """
    Submit video to HuggingFace API for DRS analysis.
    Returns dict with verdict, speed, and replay_link.
    """
    if not HF_API_TOKEN:
        raise ValueError("HuggingFace API token not set in environment variables")
    
    try:
        headers = {
            "Authorization": f"Bearer {HF_API_TOKEN}",
            "Content-Type": "application/json"
        }
        payload = {
            "video_url": video_path
        }
        response = requests.post(HF_API_URL, json=payload, headers=headers)
        
        if response.status_code == 200:
            return response.json()
        else:
            raise Exception(f"HuggingFace API error: {response.text}")
    except Exception as e:
        print(f"Error submitting to HuggingFace: {str(e)}")
        return {"verdict": "Unknown", "speed": 0.0, "replay_link": ""}