""" š¬ Video Reasoning Demo - HuggingFace Spaces Version This demo showcases the model's ability to reason over long videos using tool calls. Designed with a modern, sleek interface featuring glassmorphism and smooth animations. Adapted for HuggingFace Spaces deployment with videos hosted on HF Dataset. """ import json import re import os from typing import Any, Dict, List, Optional from dataclasses import dataclass import gradio as gr # ============================================================================ # Configuration # ============================================================================ # HuggingFace Dataset URL for videos HF_DATASET_URL = "https://huggingface.co/datasets/longvideotool/LongVT-Demo/resolve/main" # Pre-parsed sample data (embedded to avoid file dependencies) SAMPLE_DATA = [ { "id": "sample_1", "video_filename": "_FLyZoj7YAc.mp4", "question": "Which animal is shown first lying motionless on a concrete surface with a group posing beside it, and later strapped onto a tractor being transported? Think first, call **crop_video** if needed, then answer.", "thinking_steps": [ "The video presents a rapid succession of various animals in different settings, often with a heat-map overlay indicating \"interest points.\" We observe sequences featuring elephants interacting with vehicles around [0:20s ā 1:00s], followed by a segment with large fish, including one being caught by a boat around [1:45s ā 2:20s]. Later, there are shots of wolves and lions in various landscapes from approximately [3:00s ā 3:40s]. Towards the end, an animal is seen motionless on concrete with people posing, which then transitions to it being strapped to a tractor. Given the question's specific details about lying motionless on a concrete surface with a group posing, I will examine the video segment around [2:48s ā 2:55s] to precisely identify the animal in the initial pose, as this window should capture the onset of this unique scene.", "The current video segment from [300.30s ā 317.60s] shows a fishing boat on the water around 5:00, followed by a close-up of a fishing reel around 5:05, then black and white images of people posing with large fish, specifically tuna, from approximately 5:10 to 5:20. While the segment concludes with a person being carried on a mat, which partially matches the \"strapped onto a tractor\" part of the question, this window does not contain any animal lying motionless on a concrete surface with a group posing. This evidence clearly indicates that the scene described in the question does not occur within this time frame. My earlier hypothesis about the relevant scene occurring around [2:48s ā 2:55s] was incorrect, and the relevant event must be located significantly earlier than initially estimated. Therefore, this window was mis-localized, and a revised search is needed to find the actual moment of the animal lying motionless.", "This video segment from [172.00s ā 191.00s] provides direct visual evidence for the question. Specifically, from approximately 186.00s to 190.00s, an alligator is clearly shown lying motionless on a concrete surface. Additionally, around 182.00s, a group of people is seen posing with the same alligator, which directly addresses the \"group posing beside it\" part of the query. This window perfectly matches the initial scenario described in the question, confirming the identity of the animal. My earlier global skim had missed this crucial segment, but this targeted search precisely captured the scene. This window was well-localized and fully sufficient for identifying the animal and the specific posing action." ], "tool_calls": [ {"arguments": {"start_time": 300.3, "end_time": 317.6}}, {"arguments": {"start_time": 172.0, "end_time": 191.0}} ], "final_answer": "An alligator.", "ground_truth": "An alligator.", "scores": {"accuracy": 1.0, "format": 1.0, "time": 0.2632} }, { "id": "sample_2", "video_filename": "eTa1LAtqfsc.mp4", "question": "What single Cyrillic word is written on the fuel tank of the truck that is refueled, later drops its trailer on a forest road, and then continues toward the excavation site? Think first, call **crop_video** if needed, then answer.", "thinking_steps": [ "The video begins with a title card before transitioning to a top-down view of a snowy, industrial landscape, likely a mining operation, around [15s ā 50s]. A large snowmobile-like vehicle is seen traveling on a snowy path around [1:00s ā 1:30s], and the camera then follows several dump trucks navigating muddy roads [1:45s ā 2:30s]. Around [3:00s ā 3:30s], one of the trucks is shown being refueled at a fuel station. Later, around [5:45s ā 5:55s], a truck drops its trailer on a forest road, before the same or a similar truck continues towards the excavation site around [5:57s ā 6:00s]. To identify the Cyrillic word on the fuel tank of the truck that is refueled, I will crop the video segment around [5:45s ā 5:55s] to get a closer look at the fuel tank during the refueling process.", "The video segment from [345.00s ā 355.00s] shows the truck, identifiable as a Volvo, approaching and then reversing to drop its trailer on the forest road. While the trailer is clearly visible during this segment, the fuel tank of the truck itself is not prominently displayed. There are no visible Cyrillic words on the fuel tank or anywhere else on the truck in these frames. The action is focused on the trailer drop rather than the truck's fuel tank. This window was mis-localized, as it captured the trailer drop but not the refueling or the fuel tank with the Cyrillic word. A revised search is needed to examine the actual refueling segment more closely.", "The video segment [357.00s ā 441.00s] clearly shows the truck, a Volvo, continuing its journey towards an excavation site after dropping its trailer. Around 360.00s to 365.00s, the fuel tank of the truck is visible, and the Cyrillic word \"ŠŠŠŠŠŠ¬\" (meaning \"Diesel\") is clearly written on the fuel tank. This directly matches the description of the truck that is refueled, drops its trailer, and continues toward the excavation site. This window was well-localized and fully suffices for identifying the Cyrillic word on the fuel tank." ], "tool_calls": [ {"arguments": {"start_time": 345.0, "end_time": 355.0}}, {"arguments": {"start_time": 357.0, "end_time": 441.0}} ], "final_answer": "ŠŠŠŠŠŠ¬", "ground_truth": "ŠŠŠŠŠŠ¬", "scores": {"accuracy": 1.0, "format": 1.0, "time": 0.1190} }, { "id": "sample_3", "video_filename": "Erph1L_XwVQ.mp4", "question": "Which two-word phrase is displayed on a plain white background right after the split-screen maps contrasting the \"White primary\" and \"General election\" voting areas disappear? Think first, call **crop_video** if needed, then answer.", "thinking_steps": [ "The video opens with title cards and a brief clip of people kayaking, then introduces the speaker, Lawrence Lessig, who proceeds to discuss issues of democracy and voting rights, often juxtaposing historical images with present-day visuals [35.0s ā 190.0s]. He covers topics like the \"White primary\" and \"General election\" through split-screen maps and textual information around [195.0s ā 219.0s]. The speaker then transitions to discuss \"Relevant Funders\" and how campaign finance reforms could impact democracy, displaying relevant statistics and maps [220.0s ā 320.0s], before concluding with a call to action to reclaim democracy [325.0s ā 345.0s]. To pinpoint the exact phrase after the \"White primary\" and \"General election\" maps, I will examine the segment immediately following their disappearance, focusing on the visual transition. I will crop the video from [218.0s ā 222.0s] to capture this transition and the potential answer.", "The video segment from [218.00s ā 222.00s] clearly shows the split-screen maps of the \"White primary\" and \"General election\" voting areas, as described in the question, ongoing at the beginning of this window. Following these maps, there is a brief black screen transition, after which the phrase \"not totally\" appears centered on a plain white background. This phrase then transitions into an illustration of a man turning a knob, which is the visual presented immediately after the maps. My initial hypothesis was to find the answer within this window; however, the crucial visual element \"disappearing\" is not fully captured here, as the maps are still visible at the start of this segment. This window provides part of the answer, but the precise moment the maps disappear is either at the very beginning of this segment or just before, indicating the need to extend the search slightly later. This window was slightly mis-localized as it captured the transition *after* the maps but not the maps' complete disappearance; therefore, I will need to inspect a slightly later segment to find the exact point of disappearance and the subsequent display of the two-word phrase.", "This video segment, from [220.000, 226.000], provides clear evidence. The split-screen maps contrasting the \"White primary\" and \"General election\" voting areas are visible at the beginning of the segment. These maps then disappear around [221.00s], after which the phrase \"not totally\" appears on a plain white background from approximately [222.00s] until about [224.00s], exactly as before. This window fully confirms the earlier identification of the phrase and its visual context. My initial assessment was correct that the phrase \"not totally\" is displayed; revised: the previous window was indeed slightly mis-localized as it captured the transition *after* the maps but not the maps' complete disappearance, whereas this segment perfectly captures the disappearance of the maps and the immediate subsequent display of the phrase on a white background. This window was well-localized and fully suffices for its subgoal, capturing the precise moment the maps disappear and the subsequent appearance of the two-word phrase." ], "tool_calls": [ {"arguments": {"start_time": 218.0, "end_time": 222.0}}, {"arguments": {"start_time": 220.0, "end_time": 226.0}} ], "final_answer": "not totally", "ground_truth": "not totally", "scores": {"accuracy": 1.0, "format": 1.0, "time": 0.6250} }, { "id": "sample_4", "video_filename": "_jHeXEJseBk.mp4", "question": "What laptop brand is presented first while a gloved hand uses its ScreenPad 2.0 touchpad and later while it balances on a skateboard ramp beside the NVIDIA 2 GB MX250 text? Think first, call **crop_video** if needed, then answer.", "thinking_steps": [ "The video presents a countdown of laptops, starting with the Acer Swift 3, showcasing its design and screen around [0:00s ā 0:05s]. This is followed by the Asus VivoBook S15, highlighting its unique ScreenPad 2.0 touchpad, which a gloved hand is seen interacting with at approximately [5:14s ā 5:18s]. The same VivoBook later appearsbalanced on a skateboard ramp next to text referencing the NVIDIA 2 GB MX250 graphics chip, around [5:50s ā 5:54s]. This specific sequence of the Asus VivoBook, including both the ScreenPad interaction and the MX250 context, precisely matches the query's description. This window successfully captures the key elements mentioned in the question, confirming the brand and specific features. No further localization is needed as the critical information for identifying the brand and matching all described elements is contained within this segment.", "The video segment from [314.000s ā 358.000s] displays various laptops, including an HP model around ā320sā325s and a Lenovo Yoga C740 from ā340sā345s. While the HP screen shows a \"ScreenPad 2.0\" label, the visual of a gloved hand actively using it is not present in these frames, nor is any laptop shown balancing on a skateboard ramp with NVIDIA 2 GB MX250 text. This window appears to showcase different laptops and their features, but not the specific Asus VivoBook S15 or the requested actions. This evidence suggests that the critical sequence of the Asus VivoBook demonstrating its ScreenPad 2.0 and then appearing on the skateboard ramp (around [5:14s ā 5:54s]) is not present here, revising the earlier hypothesis that the Asus VivoBook was necessarily presented in that order within the entire video. This window was mis-localized for the specific Asus VivoBook sequence, although it does show a laptop with ScreenPad 2.0. The previous localization at [5:14s ā 5:18s] and [5:50s ā 5:54s] for the ScreenPad and MX250 contexts must therefore be the intended reference points, implying the question is asking about those specific instances rather than locating the brand name in this particular segment." ], "tool_calls": [ {"arguments": {"start_time": 314.0, "end_time": 358.0}} ], "final_answer": "Asus", "ground_truth": "ASUS VivoBook", "scores": {"accuracy": 1.0, "format": 1.0, "time": 0.0} }, { "id": "sample_5", "video_filename": "_JskH8-GvyU.mp4", "question": "After the TicWatch earlier shows the music playback screen for \"Pontiac Shuffle,\" to which contact does the user later dictate a text message using the watch? Think first, call **crop_video** if needed, then answer.", "thinking_steps": [ "The video begins with an intro screen, then shows the unboxing of a TicWatch, including its various features and accessories [10.00s ā 200.00s]. The user pairs the watch with a phone and demonstrates different applications like weather, fitness tracking, and voice commands [200.00s ā 460.00s]. Later, the watch is shown displaying notifications and with a music playback screen for \"Pontiac Shuffle\" around [470.00s ā 473.00s]. To find when the user dictates a text message *after* this, I will focus on the period immediately following the music playback, specifically looking for text message composition on the watch [474.00s ā 480.00s].", "This window [474.000,480.000] shows the watch displaying a stopwatch application, with times like 00:00, 00:04, and 00:05 visible on the screen. There is no music playback screen for \"Pontiac Shuffle\" present in these frames, nor are there any indications of a text message being dictated or displayed. This evidence indicates that the current window is not the correct segment of the video for answering the question, as it does not contain the specified \"Pontiac Shuffle\" music playback which is a prerequisite condition mentioned in the full prompt. My earlier hypothesis to look immediately after the music playback was misdirected, as the music playback event itself is not present here. Therefore, this window was mis-localized, and a revised search is needed to find the actual moment of the \"Pontiac Shuffle\" music playback screen at a later point in the video, after which I can then look for the dictated text message." ], "tool_calls": [ {"arguments": {"start_time": 474.0, "end_time": 480.0}} ], "final_answer": "Vijay Vyas", "ground_truth": "Vijay Vyas", "scores": {"accuracy": 1.0, "format": 1.0, "time": 0.0} } ] @dataclass class DemoConfig: """Demo configuration""" title: str = "š¬ Long Video Reasoning" subtitle: str = "Explore how AI reasons through long videos step by step" samples: List[Dict[str, Any]] = None def __post_init__(self): if self.samples is None: self.samples = SAMPLE_DATA # ============================================================================ # UI Components # ============================================================================ def create_thinking_html(thinking_steps: List[str], tool_calls: List[Dict]) -> str: """Create beautiful HTML for thinking process visualization""" html = '
Incentivizing "Thinking with Long Videos" via Native Tool Calling
See how LongVT navigates through long videos, making intelligent decisions about which segments to analyze,
reasoning step by step to find answers.