dschandra commited on
Commit
3d9c57d
·
verified ·
1 Parent(s): bc2882e

Create huggingface_api.py

Browse files
Files changed (1) hide show
  1. utils/huggingface_api.py +37 -0
utils/huggingface_api.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # backend/utils/huggingface_api.py
2
+ import requests
3
+ import os
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+
9
+ # HuggingFace API configuration
10
+ HF_API_URL = "https://api.huggingface.co/submit_match" # Replace with actual endpoint
11
+ HF_API_TOKEN = os.getenv("HF_API_TOKEN")
12
+
13
+ def submit_to_huggingface(video_path: str) -> dict:
14
+ """
15
+ Submit video to HuggingFace API for DRS analysis.
16
+ Returns dict with verdict, speed, and replay_link.
17
+ """
18
+ if not HF_API_TOKEN:
19
+ raise ValueError("HuggingFace API token not set in environment variables")
20
+
21
+ try:
22
+ headers = {
23
+ "Authorization": f"Bearer {HF_API_TOKEN}",
24
+ "Content-Type": "application/json"
25
+ }
26
+ payload = {
27
+ "video_url": video_path
28
+ }
29
+ response = requests.post(HF_API_URL, json=payload, headers=headers)
30
+
31
+ if response.status_code == 200:
32
+ return response.json()
33
+ else:
34
+ raise Exception(f"HuggingFace API error: {response.text}")
35
+ except Exception as e:
36
+ print(f"Error submitting to HuggingFace: {str(e)}")
37
+ return {"verdict": "Unknown", "speed": 0.0, "replay_link": ""}