File size: 2,064 Bytes
0547e67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
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()

@spaces.GPU(duration=120)  # 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()