ai_generation_bot / models /text_to_video.py
Prashanthsrn's picture
Upload 4 files
52346ac verified
raw
history blame contribute delete
829 Bytes
import tempfile
import os
try:
from modelscope.pipelines import pipeline
from modelscope.outputs import OutputKeys
MODELSCOPE_AVAILABLE = True
except ImportError:
MODELSCOPE_AVAILABLE = False
def generate_video(prompt):
if not MODELSCOPE_AVAILABLE:
raise ImportError("The modelscope library is not installed or there was an error importing it. "
"Please make sure all dependencies are correctly installed.")
pipe = pipeline('text-to-video-synthesis', 'damo/text-to-video-synthesis')
output = pipe({'text': prompt})
video = output[OutputKeys.OUTPUT_VIDEO]
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as temp_file:
temp_path = temp_file.name
with open(temp_path, 'wb') as f:
f.write(video)
return temp_path