File size: 1,398 Bytes
474e88e
1c04df8
 
474e88e
1c04df8
 
474e88e
ac409c4
 
 
 
 
 
 
 
 
 
 
 
1c04df8
474e88e
 
ac409c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474e88e
 
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
import gradio as gr
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

# Load ModelScope's Text-to-Video Model
video_model = pipeline(Tasks.text_to_video_synthesis, model='damo/text-to-video-synthesis')

def generate_video(prompt, style, duration, image):
    # Modify prompt with style
    prompt = f"{prompt}, in {style} style"
    
    # Prepare inputs
    inputs = {'text': prompt, 'duration': duration}
    
    if image:
        inputs['image'] = image  # Use uploaded image if provided

    # Generate video
    result = video_model(inputs)
    return result["output_video"]

# Gradio UI
with gr.Blocks() as iface:
    gr.Markdown("# 🎥 AI Text-to-Video Generator")
    gr.Markdown("Enter a prompt, choose a style, and generate a video!")

    with gr.Row():
        prompt = gr.Textbox(label="Enter text prompt", placeholder="A futuristic city with flying cars")
        style = gr.Dropdown(["Realistic", "Cartoon", "Anime"], label="Select Video Style", value="Realistic")

    duration = gr.Slider(1, 10, step=1, label="Video Duration (Seconds)", value=5)
    image = gr.Image(label="Upload an Image (Optional)", type="filepath")

    generate_btn = gr.Button("Generate Video")

    output_video = gr.Video(label="Generated Video")

    generate_btn.click(generate_video, inputs=[prompt, style, duration, image], outputs=output_video)

iface.launch()