# 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": ""}