import gradio as gr def generate_video(text_prompt, token): """Generate video from text using the Wan-AI/Wan2.2-TI2V-5B model""" if not token: return None, "Please sign in to use this feature." try: # Use Gradio's client to call the model client = gr.Interface.load("models/Wan-AI/Wan2.2-TI2V-5B", hf_token=token) result = client(text_prompt) return result, "Video generated successfully!" except Exception as e: return None, f"Error generating video: {str(e)}" with gr.Blocks(fill_height=True) as demo: with gr.Sidebar(): gr.Markdown("# Text-to-Video Generator") gr.Markdown("This Space showcases the Wan-AI/Wan2.2-TI2V-5B model, served by the replicate API. Sign in with your Hugging Face account to use this API.") button = gr.LoginButton("Sign in") with gr.Column(): gr.Markdown("## Generate Video from Text") gr.Markdown("Enter a text description and generate a video using AI!") text_input = gr.Textbox( label="Text Prompt", placeholder="Describe the video you want to generate...", lines=3 ) generate_btn = gr.Button("Generate Video", variant="primary") with gr.Row(): video_output = gr.Video(label="Generated Video") status_output = gr.Textbox(label="Status", interactive=False) generate_btn.click( fn=generate_video, inputs=[text_input, button], outputs=[video_output, status_output] ) demo.launch()