import os import gradio as gr import spaces from utils.gradio_utils import * import argparse GRADIO_CACHE = "" parser = argparse.ArgumentParser() parser.add_argument('--public_access', action='store_true') args = parser.parse_args() streaming_svd = StreamingSVD(load_argv=False) on_huggingspace = os.environ.get("SPACE_AUTHOR_NAME") == "PAIR" examples = [ ["Experience the dance of jellyfish: float through mesmerizing swarms of jellyfish, pulsating with otherworldly grace and beauty.", "200 - frames (recommended)", 33, None, None], ["Dive into the depths of the ocean: explore vibrant coral reefs, mysterious underwater caves, and the mesmerizing creatures that call the sea home.", "200 - frames (recommended)", 33, None, None], ["A cute cat.", "200 - frames (recommended)", 33, None, None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test1.jpg", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test2.jpg", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test3.png", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test4.png", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test5.jpg", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test6.png", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test7.jpg", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test8.jpg", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test9.jpg", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test10.jpg", None], ["", "200 - frames (recommended)", 33, "__assets__/gradio_cached_examples/test11.jpg", None], ] @spaces.GPU(duration=300) def generate(prompt, num_frames, seed, image: np.ndarray): if num_frames == [] or num_frames is None: num_frames = 50 else: num_frames = int(num_frames.split(" ")[0]) if num_frames > 200: # and on_huggingspace: num_frames = 200 if image is None: image = text_to_image_gradio( prompt=prompt, streaming_svd=streaming_svd, seed=seed) video_file_stage_one = image_to_video_vfi_gradio( img=image, num_frames=num_frames, streaming_svd=streaming_svd, seed=seed, gradio_cache=GRADIO_CACHE) expanded_size, orig_size, scaled_outpainted_image = retrieve_intermediate_data(video_file_stage_one) video_file_stage_two = enhance_video_vfi_gradio( img=scaled_outpainted_image, video=video_file_stage_one.replace("__cropped__", "__expanded__"), num_frames=24, streaming_svd=streaming_svd, seed=seed, expanded_size=expanded_size, orig_size=orig_size, gradio_cache=GRADIO_CACHE) return image, video_file_stage_one, video_file_stage_two @spaces.GPU(duration=300) def enhance(prompt, num_frames, seed, image: np.ndarray, video:str): if num_frames == [] or num_frames is None: num_frames = 50 else: num_frames = int(num_frames.split(" ")[0]) if num_frames > 200: # and on_huggingspace: num_frames = 200 # User directly applied Long Video Generation (without preview) with Flux. if image is None: image = text_to_image_gradio( prompt=prompt, streaming_svd=streaming_svd, seed=seed) # User directly applied Long Video Generation (without preview) with or without Flux. if video is None: video = image_to_video_gradio( img=image, num_frames=(num_frames+1) // 2, streaming_svd=streaming_svd, seed=seed, gradio_cache=GRADIO_CACHE) expanded_size, orig_size, scaled_outpainted_image = retrieve_intermediate_data(video) # Here the video is path and image is numpy array video_file_stage_two = enhance_video_vfi_gradio( img=scaled_outpainted_image, video=video.replace("__cropped__", "__expanded__"), num_frames=num_frames, streaming_svd=streaming_svd, seed=seed, expanded_size=expanded_size, orig_size=orig_size, gradio_cache=GRADIO_CACHE) return image, video_file_stage_two with gr.Blocks() as demo: GRADIO_CACHE = demo.GRADIO_CACHE gr.HTML("""
For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.