""" 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()