Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from utils import generate_video | |
| import spaces | |
| import os | |
| from huggingface_hub import login | |
| # Login to Hugging Face (users need to provide their token) | |
| hf_token = os.getenv("HF_TOKEN") | |
| if hf_token: | |
| login(hf_token) | |
| else: | |
| raise ValueError("Please set HF_TOKEN environment variable for model access") | |
| # Compile the model with ZeroGPU AoT for speed | |
| from utils import compile_model | |
| compiled_model = compile_model() | |
| # Allow time for video generation | |
| def generate(prompt: str, user: str): | |
| # Generate video from prompt | |
| video_path = generate_video(prompt, compiled_model) | |
| # Save to user's account (placeholder - integrate with HF Hub or database) | |
| return video_path | |
| with gr.Blocks(title="Fast Text-to-Video Generator", theme=gr.themes.Soft()) as demo: | |
| gr.HTML(""" | |
| <h1 style='text-align: center'>Fast Text-to-Video Generator</h1> | |
| <p style='text-align: center'>Login to your account to generate personalized videos. Built with <a href='https://huggingface.co/spaces/akhaliq/anycoder' target='_blank'>anycoder</a>.</p> | |
| """) | |
| login_btn = gr.LoginButton("Sign in with Hugging Face") | |
| with gr.Row(visible=False) as main_ui: | |
| prompt_input = gr.Textbox(label="Enter your text prompt", placeholder="A cat playing in a garden") | |
| generate_btn = gr.Button("Generate Video") | |
| video_output = gr.Video(label="Generated Video") | |
| status = gr.Textbox(label="Status", interactive=False) | |
| def show_ui(): | |
| return gr.Row(visible=True) | |
| def create_video(prompt, request: gr.Request): | |
| if not request.username: | |
| return None, "Please login first" | |
| status = "Generating video... (this is very fast!)" | |
| video = generate(prompt, request.username) | |
| status = "Video generated successfully!" | |
| return video, status | |
| login_btn.click(show_ui, outputs=main_ui) | |
| generate_btn.click(create_video, inputs=[prompt_input], outputs=[video_output, status]) | |
| if __name__ == "__main__": | |
| demo.launch() |