Create svision_client.py
Browse files- svision_client.py +21 -0
svision_client.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
HF_SPACE_URL = "https://hf.space/embed/VeuReu/svision/api/"
|
| 5 |
+
HF_TOKEN = os.environ.get("HF_TOKEN") # Asegúrate de que tu token está en esta variable de entorno
|
| 6 |
+
|
| 7 |
+
def call_svision(endpoint: str, inputs: list):
|
| 8 |
+
url = HF_SPACE_URL + endpoint
|
| 9 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"} if HF_TOKEN else {}
|
| 10 |
+
print("URL que se llama:", url)
|
| 11 |
+
print("Headers enviados:", headers)
|
| 12 |
+
response = requests.post(url, json={"data": inputs}, headers=headers)
|
| 13 |
+
response.raise_for_status()
|
| 14 |
+
return response.json()["data"]
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def extract_scenes(video_path: str, threshold: float = 30.0, offset_frames: int = 10, crop_ratio: float = 0.1):
|
| 18 |
+
print("Extrayendo escenas...")
|
| 19 |
+
result = call_svision("scenes_extraction", [video_path, threshold, offset_frames, crop_ratio])
|
| 20 |
+
print("Escenas extraídas.")
|
| 21 |
+
return result
|