1+ from typing import Any , Dict , Optional , Union
2+
3+ from huggingface_hub .inference ._common import _as_dict
14from huggingface_hub .inference ._providers ._common import (
25 BaseConversationalTask ,
36 BaseTextGenerationTask ,
7+ TaskProviderHelper ,
8+ filter_none ,
49)
10+ from huggingface_hub .utils import get_session
511
612
713_PROVIDER = "novita"
@@ -24,3 +30,27 @@ def __init__(self):
2430 def _prepare_route (self , mapped_model : str ) -> str :
2531 # there is no v1/ route for novita
2632 return "/v3/openai/chat/completions"
33+
34+
35+ class NovitaTextToVideoTask (TaskProviderHelper ):
36+ def __init__ (self ):
37+ super ().__init__ (provider = _PROVIDER , base_url = _BASE_URL , task = "text-to-video" )
38+
39+ def _prepare_route (self , mapped_model : str ) -> str :
40+ return f"/v3/hf/{ mapped_model } "
41+
42+ def _prepare_payload_as_dict (self , inputs : Any , parameters : Dict , mapped_model : str ) -> Optional [Dict ]:
43+ return {"prompt" : inputs , ** filter_none (parameters )}
44+
45+ def get_response (self , response : Union [bytes , Dict ]) -> Any :
46+ response_dict = _as_dict (response )
47+ if not (
48+ isinstance (response_dict , dict )
49+ and "video" in response_dict
50+ and isinstance (response_dict ["video" ], dict )
51+ and "video_url" in response_dict ["video" ]
52+ ):
53+ raise ValueError ("Expected response format: { 'video': { 'video_url': string } }" )
54+
55+ video_url = response_dict ["video" ]["video_url" ]
56+ return get_session ().get (video_url ).content
0 commit comments