File size: 1,481 Bytes
f0bddae
236d537
f0bddae
 
 
c804b0a
 
f0bddae
 
c804b0a
 
 
 
f0bddae
 
 
 
2ac584d
f0bddae
2ac584d
bc5887e
 
 
 
 
 
c804b0a
bc5887e
 
 
 
 
f0bddae
bc5887e
 
c804b0a
f0bddae
 
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
import gradio as gr
import os
from modelscope.pipelines import pipeline
from modelscope.outputs import OutputKeys

SECRET_TOKEN = os.getenv('SECRET_TOKEN', 'default_secret')

pipe = pipeline(task='image-to-video', model='damo/Image-to-Video', model_revision='v1.1.0')

def infer (image_in, secret_token):
    if secret_token != SECRET_TOKEN:
        raise gr.Error(f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
        
    # IMG_PATH: your image path (url or local file)
    IMG_PATH = image_in
    output_video_path = pipe(IMG_PATH, output_video='output.mp4')[OutputKeys.OUTPUT_VIDEO]
    print(output_video_path)
    return output_video_path

with gr.Blocks() as demo:
    gr.Markdown("""
    <p>
        You are currently viewing a micro-service API meant to be used by robots.<br/>
        For the human UI, please check out the <a href="https://huggingface.co/spaces/fffiloni/MS-Image2Video">original Space by Sylvain Filoni</a>.
     </p>
    """)
    secret_token = gr.Text(label='Secret', max_lines=1, placeholder='secret')
    image_in = gr.Image(
        label = "Source Image",
        source = "upload", 
        type = "filepath",
        elem_id = "image-in"
    )
    submit_btn = gr.Button("Submit")
    video_out = gr.Video(label = "Video Result", elem_id = "video-out")
    submit_btn.click(fn = infer, inputs = [image_in, secret_token], outputs = [video_out], api_name ="generate")

demo.queue(max_size=6).launch()