Arpan Tripathi commited on
add proxy downloadability checks for organics (#152)
Browse files- .env.template +2 -0
- services/scoring/server.py +106 -4
- vidaio_subnet_core/__init__.py +1 -1
.env.template
CHANGED
|
@@ -9,6 +9,8 @@ BUCKET_COMPATIBLE_SECRET_KEY="bucket personal secret key"
|
|
| 9 |
PEXELS_API_KEY="Your Pexels account api key"
|
| 10 |
WANDB_API_KEY="Your wandb api key"
|
| 11 |
ORGANIC_API_KEY="API key for authenticating organic gateway requests"
|
|
|
|
|
|
|
| 12 |
|
| 13 |
DASHBOARD_ENDPOINT=X #add dashboard endpoint here
|
| 14 |
|
|
|
|
| 9 |
PEXELS_API_KEY="Your Pexels account api key"
|
| 10 |
WANDB_API_KEY="Your wandb api key"
|
| 11 |
ORGANIC_API_KEY="API key for authenticating organic gateway requests"
|
| 12 |
+
ORGANIC_PROXY_VERIFY_DOWNLOAD_ENDPOINT="http://135.181.63.197:20000/api/v1/videos/verify_download"
|
| 13 |
+
ORGANIC_PROXY_API_KEY="API key sent to the organic proxy as X-API-Key"
|
| 14 |
|
| 15 |
DASHBOARD_ENDPOINT=X #add dashboard endpoint here
|
| 16 |
|
services/scoring/server.py
CHANGED
|
@@ -40,6 +40,11 @@ VMAF_THRESHOLD = CONFIG.score.vmaf_threshold
|
|
| 40 |
PIEAPP_SAMPLE_COUNT = CONFIG.score.pieapp_sample_count
|
| 41 |
PIEAPP_THRESHOLD = CONFIG.score.pieapp_threshold
|
| 42 |
VMAF_SAMPLE_COUNT = CONFIG.score.vmaf_sample_count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Check if vmaf_ffmpeg Docker image with libvmaf_cuda is available
|
| 45 |
VMAF_FFMPEG_AVAILABLE = is_vmaf_ffmpeg_available()
|
|
@@ -169,6 +174,39 @@ async def get_shared_session() -> aiohttp.ClientSession:
|
|
| 169 |
_shared_session = aiohttp.ClientSession(timeout=timeout, connector=connector)
|
| 170 |
return _shared_session
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
async def download_video(video_url: str, verbose: bool, session: Optional[aiohttp.ClientSession] = None) -> tuple[str, float]:
|
| 173 |
"""
|
| 174 |
Download a video from the given URL and save it to a temporary file.
|
|
@@ -2438,11 +2476,27 @@ async def score_organics_upscaling(request: OrganicsUpscalingScoringRequest) ->
|
|
| 2438 |
final_scores = []
|
| 2439 |
reasons = []
|
| 2440 |
|
|
|
|
| 2441 |
distorted_video_paths = []
|
| 2442 |
for dist_url in request.distorted_urls:
|
| 2443 |
if len(dist_url) < 10:
|
|
|
|
| 2444 |
distorted_video_paths.append(None)
|
| 2445 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2446 |
try:
|
| 2447 |
path, download_time = await download_video(dist_url, request.verbose)
|
| 2448 |
distorted_video_paths.append(path)
|
|
@@ -2450,8 +2504,8 @@ async def score_organics_upscaling(request: OrganicsUpscalingScoringRequest) ->
|
|
| 2450 |
logger.error(f"failed to download distorted video: {dist_url}, error: {e}")
|
| 2451 |
distorted_video_paths.append(None)
|
| 2452 |
|
| 2453 |
-
for idx, (ref_url, dist_path, uid, task_type) in enumerate(
|
| 2454 |
-
zip(request.reference_urls, distorted_video_paths, request.uids, request.task_types)
|
| 2455 |
):
|
| 2456 |
logger.info(f"🧩 processing {uid}.... downloading reference video.... 🧩")
|
| 2457 |
ref_path = None
|
|
@@ -2537,6 +2591,23 @@ async def score_organics_upscaling(request: OrganicsUpscalingScoringRequest) ->
|
|
| 2537 |
|
| 2538 |
# === MINER OUTPUT VALIDATION (MINER'S FAULT) ===
|
| 2539 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2540 |
# check if distorted video failed to download
|
| 2541 |
if dist_path is None:
|
| 2542 |
logger.error(f"failed to download distorted video for uid {uid}. penalizing miner.")
|
|
@@ -2785,11 +2856,27 @@ async def score_organics_compression(request: OrganicsCompressionScoringRequest)
|
|
| 2785 |
final_scores = []
|
| 2786 |
reasons = []
|
| 2787 |
|
|
|
|
| 2788 |
distorted_video_paths = []
|
| 2789 |
for dist_url in request.distorted_urls:
|
| 2790 |
if len(dist_url) < 10:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2791 |
distorted_video_paths.append(None)
|
| 2792 |
continue
|
|
|
|
| 2793 |
try:
|
| 2794 |
path, download_time = await download_video(dist_url, request.verbose)
|
| 2795 |
distorted_video_paths.append(path)
|
|
@@ -2802,9 +2889,9 @@ async def score_organics_compression(request: OrganicsCompressionScoringRequest)
|
|
| 2802 |
codec_modes = request.codec_modes if request.codec_modes else ["CRF"] * len(request.uids)
|
| 2803 |
target_bitrates = request.target_bitrates if request.target_bitrates else [10.0] * len(request.uids)
|
| 2804 |
|
| 2805 |
-
for idx, (ref_url, dist_path, uid, vmaf_threshold, target_codec, codec_mode, target_bitrate) in enumerate(
|
| 2806 |
zip(request.reference_urls, distorted_video_paths, request.uids, request.vmaf_thresholds,
|
| 2807 |
-
target_codecs, codec_modes, target_bitrates)
|
| 2808 |
):
|
| 2809 |
logger.info(f"🧩 processing {uid}.... downloading reference video.... 🧩")
|
| 2810 |
ref_path = None
|
|
@@ -2869,6 +2956,21 @@ async def score_organics_compression(request: OrganicsCompressionScoringRequest)
|
|
| 2869 |
|
| 2870 |
# === MINER OUTPUT VALIDATION (MINER'S FAULT) ===
|
| 2871 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2872 |
# check if distorted video failed to download
|
| 2873 |
if dist_path is None:
|
| 2874 |
logger.error(f"failed to download distorted video for uid {uid}. penalizing miner.")
|
|
|
|
| 40 |
PIEAPP_SAMPLE_COUNT = CONFIG.score.pieapp_sample_count
|
| 41 |
PIEAPP_THRESHOLD = CONFIG.score.pieapp_threshold
|
| 42 |
VMAF_SAMPLE_COUNT = CONFIG.score.vmaf_sample_count
|
| 43 |
+
ORGANIC_PROXY_VERIFY_DOWNLOAD_ENDPOINT = os.getenv(
|
| 44 |
+
"ORGANIC_PROXY_VERIFY_DOWNLOAD_ENDPOINT",
|
| 45 |
+
"http://135.181.63.197:20000/api/v1/videos/verify_download",
|
| 46 |
+
)
|
| 47 |
+
ORGANIC_PROXY_API_KEY = os.getenv("ORGANIC_PROXY_API_KEY", "")
|
| 48 |
|
| 49 |
# Check if vmaf_ffmpeg Docker image with libvmaf_cuda is available
|
| 50 |
VMAF_FFMPEG_AVAILABLE = is_vmaf_ffmpeg_available()
|
|
|
|
| 174 |
_shared_session = aiohttp.ClientSession(timeout=timeout, connector=connector)
|
| 175 |
return _shared_session
|
| 176 |
|
| 177 |
+
async def verify_organic_proxy_download(video_url: str, session: Optional[aiohttp.ClientSession] = None) -> bool:
|
| 178 |
+
"""Check whether the organic proxy can download a miner's output URL."""
|
| 179 |
+
verify_session = session or await get_shared_session()
|
| 180 |
+
headers = {"X-API-Key": ORGANIC_PROXY_API_KEY}
|
| 181 |
+
|
| 182 |
+
async with verify_session.post(
|
| 183 |
+
ORGANIC_PROXY_VERIFY_DOWNLOAD_ENDPOINT,
|
| 184 |
+
json={"video_url": video_url},
|
| 185 |
+
headers=headers,
|
| 186 |
+
timeout=aiohttp.ClientTimeout(total=30),
|
| 187 |
+
) as response:
|
| 188 |
+
if response.status != 200:
|
| 189 |
+
response_text = await response.text()
|
| 190 |
+
raise Exception(
|
| 191 |
+
f"Organic proxy download verification failed. HTTP status: {response.status}, "
|
| 192 |
+
f"response: {response_text[:500]}"
|
| 193 |
+
)
|
| 194 |
+
else:
|
| 195 |
+
logger.info(f"Organic proxy download verification succeeded for {video_url}")
|
| 196 |
+
|
| 197 |
+
response_data = await response.json()
|
| 198 |
+
downloadable = response_data.get("downloadable")
|
| 199 |
+
if not isinstance(downloadable, bool):
|
| 200 |
+
raise Exception("Organic proxy download verification response is missing a boolean downloadable field")
|
| 201 |
+
|
| 202 |
+
if not downloadable:
|
| 203 |
+
logger.warning(
|
| 204 |
+
f"Organic proxy could not download {video_url}: "
|
| 205 |
+
f"{response_data.get('reason', 'no reason provided')}"
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
return downloadable
|
| 209 |
+
|
| 210 |
async def download_video(video_url: str, verbose: bool, session: Optional[aiohttp.ClientSession] = None) -> tuple[str, float]:
|
| 211 |
"""
|
| 212 |
Download a video from the given URL and save it to a temporary file.
|
|
|
|
| 2476 |
final_scores = []
|
| 2477 |
reasons = []
|
| 2478 |
|
| 2479 |
+
proxy_downloadable_results = []
|
| 2480 |
distorted_video_paths = []
|
| 2481 |
for dist_url in request.distorted_urls:
|
| 2482 |
if len(dist_url) < 10:
|
| 2483 |
+
proxy_downloadable_results.append(True)
|
| 2484 |
distorted_video_paths.append(None)
|
| 2485 |
continue
|
| 2486 |
+
try:
|
| 2487 |
+
proxy_downloadable = await verify_organic_proxy_download(dist_url)
|
| 2488 |
+
except Exception as e:
|
| 2489 |
+
logger.warning(
|
| 2490 |
+
f"organic proxy download verification unavailable for {dist_url}; "
|
| 2491 |
+
f"bypassing check and continuing scoring. error: {e}"
|
| 2492 |
+
)
|
| 2493 |
+
proxy_downloadable = True
|
| 2494 |
+
|
| 2495 |
+
proxy_downloadable_results.append(proxy_downloadable)
|
| 2496 |
+
if not proxy_downloadable:
|
| 2497 |
+
distorted_video_paths.append(None)
|
| 2498 |
+
continue
|
| 2499 |
+
|
| 2500 |
try:
|
| 2501 |
path, download_time = await download_video(dist_url, request.verbose)
|
| 2502 |
distorted_video_paths.append(path)
|
|
|
|
| 2504 |
logger.error(f"failed to download distorted video: {dist_url}, error: {e}")
|
| 2505 |
distorted_video_paths.append(None)
|
| 2506 |
|
| 2507 |
+
for idx, (ref_url, dist_path, uid, task_type, proxy_downloadable) in enumerate(
|
| 2508 |
+
zip(request.reference_urls, distorted_video_paths, request.uids, request.task_types, proxy_downloadable_results)
|
| 2509 |
):
|
| 2510 |
logger.info(f"🧩 processing {uid}.... downloading reference video.... 🧩")
|
| 2511 |
ref_path = None
|
|
|
|
| 2591 |
|
| 2592 |
# === MINER OUTPUT VALIDATION (MINER'S FAULT) ===
|
| 2593 |
try:
|
| 2594 |
+
if proxy_downloadable is None:
|
| 2595 |
+
logger.warning(
|
| 2596 |
+
f"organic proxy download verification unavailable for uid {uid}; "
|
| 2597 |
+
"bypassing check and continuing scoring."
|
| 2598 |
+
)
|
| 2599 |
+
proxy_downloadable = True
|
| 2600 |
+
|
| 2601 |
+
if not proxy_downloadable:
|
| 2602 |
+
logger.error(f"organic proxy failed to download distorted video for uid {uid}. penalizing miner.")
|
| 2603 |
+
reasons.append(f"MINER FAILURE: distorted video is not downloadable through organic proxy via endpoint: {ORGANIC_PROXY_VERIFY_DOWNLOAD_ENDPOINT}, miner is recommended to whitelist organic proxy IP in S3 compatible storage")
|
| 2604 |
+
vmaf_scores.append(0.0)
|
| 2605 |
+
pieapp_scores.append(0.0)
|
| 2606 |
+
quality_scores.append(0.0)
|
| 2607 |
+
length_scores.append(0.0)
|
| 2608 |
+
final_scores.append(0.0)
|
| 2609 |
+
continue
|
| 2610 |
+
|
| 2611 |
# check if distorted video failed to download
|
| 2612 |
if dist_path is None:
|
| 2613 |
logger.error(f"failed to download distorted video for uid {uid}. penalizing miner.")
|
|
|
|
| 2856 |
final_scores = []
|
| 2857 |
reasons = []
|
| 2858 |
|
| 2859 |
+
proxy_downloadable_results = []
|
| 2860 |
distorted_video_paths = []
|
| 2861 |
for dist_url in request.distorted_urls:
|
| 2862 |
if len(dist_url) < 10:
|
| 2863 |
+
proxy_downloadable_results.append(True)
|
| 2864 |
+
distorted_video_paths.append(None)
|
| 2865 |
+
continue
|
| 2866 |
+
try:
|
| 2867 |
+
proxy_downloadable = await verify_organic_proxy_download(dist_url)
|
| 2868 |
+
except Exception as e:
|
| 2869 |
+
logger.warning(
|
| 2870 |
+
f"organic proxy download verification unavailable for {dist_url}; "
|
| 2871 |
+
f"bypassing check and continuing scoring. error: {e}"
|
| 2872 |
+
)
|
| 2873 |
+
proxy_downloadable = True
|
| 2874 |
+
|
| 2875 |
+
proxy_downloadable_results.append(proxy_downloadable)
|
| 2876 |
+
if not proxy_downloadable:
|
| 2877 |
distorted_video_paths.append(None)
|
| 2878 |
continue
|
| 2879 |
+
|
| 2880 |
try:
|
| 2881 |
path, download_time = await download_video(dist_url, request.verbose)
|
| 2882 |
distorted_video_paths.append(path)
|
|
|
|
| 2889 |
codec_modes = request.codec_modes if request.codec_modes else ["CRF"] * len(request.uids)
|
| 2890 |
target_bitrates = request.target_bitrates if request.target_bitrates else [10.0] * len(request.uids)
|
| 2891 |
|
| 2892 |
+
for idx, (ref_url, dist_path, uid, vmaf_threshold, target_codec, codec_mode, target_bitrate, proxy_downloadable) in enumerate(
|
| 2893 |
zip(request.reference_urls, distorted_video_paths, request.uids, request.vmaf_thresholds,
|
| 2894 |
+
target_codecs, codec_modes, target_bitrates, proxy_downloadable_results)
|
| 2895 |
):
|
| 2896 |
logger.info(f"🧩 processing {uid}.... downloading reference video.... 🧩")
|
| 2897 |
ref_path = None
|
|
|
|
| 2956 |
|
| 2957 |
# === MINER OUTPUT VALIDATION (MINER'S FAULT) ===
|
| 2958 |
try:
|
| 2959 |
+
if proxy_downloadable is None:
|
| 2960 |
+
logger.warning(
|
| 2961 |
+
f"organic proxy download verification unavailable for uid {uid}; "
|
| 2962 |
+
"bypassing check and continuing scoring."
|
| 2963 |
+
)
|
| 2964 |
+
proxy_downloadable = True
|
| 2965 |
+
|
| 2966 |
+
if not proxy_downloadable:
|
| 2967 |
+
logger.error(f"organic proxy failed to download distorted video for uid {uid}. penalizing miner.")
|
| 2968 |
+
vmaf_scores.append(0.0)
|
| 2969 |
+
compression_rates.append(0.9999)
|
| 2970 |
+
reasons.append("MINER FAILURE: distorted video is not downloadable through organic proxy")
|
| 2971 |
+
final_scores.append(0.0)
|
| 2972 |
+
continue
|
| 2973 |
+
|
| 2974 |
# check if distorted video failed to download
|
| 2975 |
if dist_path is None:
|
| 2976 |
logger.error(f"failed to download distorted video for uid {uid}. penalizing miner.")
|
vidaio_subnet_core/__init__.py
CHANGED
|
@@ -12,7 +12,7 @@ __all__ = [
|
|
| 12 |
"CONFIG",
|
| 13 |
]
|
| 14 |
|
| 15 |
-
__version__ = "2.2.
|
| 16 |
|
| 17 |
version_split = __version__.split(".")
|
| 18 |
__spec_version__ = (
|
|
|
|
| 12 |
"CONFIG",
|
| 13 |
]
|
| 14 |
|
| 15 |
+
__version__ = "2.2.5"
|
| 16 |
|
| 17 |
version_split = __version__.split(".")
|
| 18 |
__spec_version__ = (
|