File size: 3,879 Bytes
24a09de
21fc34d
 
4335e0e
21fc34d
12937f3
 
 
 
 
21fc34d
24a09de
 
 
 
21fc34d
95709cf
21fc34d
24a09de
d673498
24a09de
21fc34d
 
95709cf
24a09de
 
48af642
21fc34d
95709cf
21fc34d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d673498
21fc34d
24a09de
21fc34d
 
 
d673498
21fc34d
24a09de
21fc34d
 
 
 
 
 
 
95709cf
21fc34d
24a09de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import spaces
import os
import gradio as gr
from video_super_resolution.scripts.inference_sr import VEnhancer_sr

examples = [
    ["examples/023_klingai_reedit.mp4", "The video shows a panda strumming a guitar on a rock by a tranquil lake at sunset. With its black-and-white fur, the panda sits against a backdrop of mountains and a vibrant sky painted in orange and pink hues. The serene scene highlights relaxation and whimsy, with the panda, guitar, and lake harmoniously positioned. The natural landscape's depth and perspective enhance the focus on the panda's peaceful interaction with the guitar.", 4, 24, 250],
    ["examples/017_klingai_reedit.mp4", "The video depicts a majestic lion with eagle-like wings standing on a grassy hill against rolling green hills and a clear sky. The lion’s golden mane contrasts with the warm hues of the scene, and its intense gaze draws focus. The detailed, fully spread wings add a fantastical element. A 'PremiumBeat' watermark appears in the lower right, hinting at the image's source. The style blends realism with fantasy, showcasing the lion's mythical nature.", 4, 24, 250],
    ["examples/016_video.mp4", "The video is a black-and-white silent film featuring two men in wheelchairs on a pier. The foreground man, in a suit and hat, holds a sign reading 'HELP CRIPPLE.' The background shows a building and a boat, with early 20th-century clothing and image quality suggesting a narrative of disability and assistance.", 4, 24, 300],
]

# Define a GPU-decorated function for enhancement
@spaces.GPU(duration=1200)
def enhance_with_gpu(input_video, input_text):
    return venhancer.enhance_a_video(input_video, input_text)

def star_demo(result_dir="./tmp/"):
    css = """#input_video {max-width: 1024px !important} #output_vid {max-width: 2048px; max-height:1280px}"""
    global venhancer
    venhancer = VEnhancer_sr(result_dir)
    
    with gr.Blocks(analytics_enabled=False, css=css) as venhancer_iface:
        gr.Markdown(
            "<div align='center'> <h1> STAR </span> </h1> \

                     <a style='font-size:18px;color: #000000' href='https://arxiv.org/abs/2501.02976'> [ArXiv] </a>\

                     <a style='font-size:18px;color: #000000' href='https://nju-pcalab.github.io/projects/STAR'> [Project Page] </a> \

                     <a style='font-size:18px;color: #000000' href='https://github.com/NJU-PCALab/STAR'> [Github] </a> </div>"
        )
        with gr.Tab(label="STAR"):
            with gr.Column():
                with gr.Row():
                    with gr.Column():
                        with gr.Row():
                            input_video = gr.Video(label="Input Video", elem_id="input_video")
                        with gr.Row():
                            input_text = gr.Text(label="Prompts")
                        end_btn = gr.Button("Generate")
                    with gr.Row():
                        output_video = gr.Video(
                            label="Generated Video", elem_id="output_vid", autoplay=True, show_share_button=True
                        )

                gr.Examples(
                    examples=examples,
                    inputs=[input_video, input_text],
                    outputs=[output_video],
                    fn=enhance_with_gpu,  # Use the GPU-decorated function
                    cache_examples=False,
                )
            end_btn.click(
                inputs=[input_video, input_text],
                outputs=[output_video],
                fn=enhance_with_gpu,  # Use the GPU-decorated function
            )

    return venhancer_iface


if __name__ == "__main__":
    result_dir = os.path.join("./", "results")
    venhancer_iface = star_demo(result_dir)
    venhancer_iface.queue(max_size=12)
    venhancer_iface.launch(max_threads=1)