Text2Vid-AI / app.py
morbiwalaq's picture
Update app.py
ac409c4 verified
raw
history blame
1.4 kB
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()