File size: 4,687 Bytes
b9ae877
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""
Visual Chronometer + NexaAPI: AI Video Generation Demo
Based on arXiv:2603.14375

HuggingFace Space: visual-chronometer-via-nexaapi
"""

import gradio as gr
import os
import requests
from nexaapi import NexaAPI

# Initialize NexaAPI client
# Get your API key at: https://nexa-api.com or https://rapidapi.com/user/nexaquency
client = NexaAPI(api_key=os.environ.get('NEXA_API_KEY', ''))

AVAILABLE_MODELS = [
    'veo-3',
    'kling-v3-pro',
    'sora',
    'wan',
]

# Example prompts inspired by Visual Chronometer paper's test cases
EXAMPLE_PROMPTS = [
    "A hummingbird hovering near a flower, natural wing speed, photorealistic",
    "A person walking naturally at normal speed through a park",
    "Water flowing over rocks in a stream, natural flow rate",
    "A cat jumping from a table to the floor, natural gravity",
    "A person falling onto a soft bed, natural gravity speed",
]


def generate_video(api_key: str, prompt: str, model: str, duration: int) -> tuple:
    """
    Generate a video using NexaAPI.
    
    Returns:
        (video_url, status_message)
    """
    if not api_key:
        return None, "❌ Please enter your NexaAPI key. Get one at https://nexa-api.com"
    
    if not prompt:
        return None, "❌ Please enter a prompt"
    
    try:
        # Use provided API key
        local_client = NexaAPI(api_key=api_key)
        
        result = local_client.generate(
            model=model,
            prompt=prompt,
            duration=duration,
            aspect_ratio='16:9',
        )
        
        status = f"""βœ… Video generated successfully!
        
πŸ“Ή Model: {model}
⏱️ Duration: {duration}s
πŸ’° Estimated cost: ~$0.05

πŸ”— Links:
  β€’ NexaAPI: https://nexa-api.com
  β€’ RapidAPI: https://rapidapi.com/user/nexaquency
  β€’ pip install nexaapi: https://pypi.org/project/nexaapi
  β€’ Paper: https://huggingface.co/papers/2603.14375
        """
        
        return result.url, status
        
    except Exception as e:
        return None, f"❌ Error: {str(e)}\n\nGet your API key at: https://nexa-api.com"


# Build Gradio interface
with gr.Blocks(title="Visual Chronometer + NexaAPI") as demo:
    gr.Markdown("""
    # 🎬 Visual Chronometer + NexaAPI: AI Video Generation Demo
    
    Based on the research paper: **["The Pulse of Motion: Measuring Physical Frame Rate from Visual Dynamics"](https://huggingface.co/papers/2603.14375)** (arXiv:2603.14375)
    
    The paper reveals that AI video generators suffer from **"Chronometric Hallucination"** β€” physically incorrect motion speeds.
    This demo lets you generate videos via **[NexaAPI](https://nexa-api.com)** (50+ models, 5Γ— cheaper than official pricing).
    """)
    
    with gr.Row():
        with gr.Column():
            api_key = gr.Textbox(
                label="NexaAPI Key",
                placeholder="Get your key at https://nexa-api.com or https://rapidapi.com/user/nexaquency",
                type="password"
            )
            prompt = gr.Textbox(
                label="Prompt",
                placeholder="Describe the video you want to generate...",
                lines=3
            )
            model = gr.Dropdown(
                label="Model",
                choices=AVAILABLE_MODELS,
                value='veo-3'
            )
            duration = gr.Slider(
                label="Duration (seconds)",
                minimum=3,
                maximum=10,
                value=5,
                step=1
            )
            generate_btn = gr.Button("🎬 Generate Video", variant="primary")
        
        with gr.Column():
            video_url = gr.Textbox(label="Generated Video URL")
            status = gr.Textbox(label="Status", lines=10)
    
    gr.Examples(
        examples=[[p] for p in EXAMPLE_PROMPTS],
        inputs=[prompt],
        label="Example Prompts (from Visual Chronometer paper)"
    )
    
    generate_btn.click(
        fn=generate_video,
        inputs=[api_key, prompt, model, duration],
        outputs=[video_url, status]
    )
    
    gr.Markdown("""
    ---
    ## Links
    
    | Resource | Link |
    |---|---|
    | 🌐 NexaAPI | [nexa-api.com](https://nexa-api.com) |
    | πŸš€ RapidAPI | [rapidapi.com/user/nexaquency](https://rapidapi.com/user/nexaquency) |
    | 🐍 Python SDK | `pip install nexaapi` |
    | πŸ“¦ Node.js SDK | `npm install nexaapi` |
    | πŸ“„ Paper | [arXiv:2603.14375](https://huggingface.co/papers/2603.14375) |
    | πŸ’» Visual Chronometer | [GitHub](https://github.com/taco-group/Visual_Chronometer) |
    
    *Source: arXiv:2603.14375 | Fetched: 2026-03-27*
    """)


if __name__ == '__main__':
    demo.launch()