Skip to content

Conversation

SolitaryThinker
Copy link
Collaborator

replaces #740

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SolitaryThinker, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the FastVideo framework by integrating a new Gradio-based local inference demo. This demo provides a user-friendly web interface for generating videos from text prompts, complete with various customization options and performance metrics. Additionally, the changes include improvements to video output file handling and a clearer structure for Gradio examples within the repository.

Highlights

  • Gradio Local Inference Demo: Introduced a new Gradio-based web interface for local video generation, allowing users to create videos from text prompts with customizable parameters.
  • Enhanced Video Output Management: Refactored the VideoGenerator to include a new _prepare_output_path method, which sanitizes video filenames, prevents overwrites, and ensures proper directory creation for saved videos.
  • Gradio UI Features: The new demo provides a user-friendly interface with options for prompt input, negative prompts, adjustable video dimensions, frame count, guidance scale, and seed control, along with a timing breakdown display.
  • Codebase Restructuring: Existing Gradio examples were moved into a new serving subdirectory to better organize the project's inference examples.
  • Improved Error Messaging: The error message for missing Video Sparse Attention backend now includes a direct link to installation instructions, improving user experience for dependency issues.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a Gradio-based local inference demo, which is a great addition for showcasing the capabilities of FastVideo. The implementation is comprehensive, including a web UI, backend logic, and supporting assets. My review focuses on improving robustness, portability, and maintainability. Key suggestions include fixing a critical import error, addressing hardcoded paths, improving the video-saving logic to be more reliable, and making the code less brittle. There are also some suggestions to enhance the API of VideoGenerator to make it more user-friendly.

params.width = int(width)

if randomize_seed:
params.seed = torch.randint(0, 1000000, (1, )).item()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The torch library is used here to generate a random integer, but it has not been imported in this file. This will raise a NameError when randomize_seed is checked. You should add import torch at the top of the file to resolve this.

print(f"Warning: Could not read {filepath}: {e}")
return prompts, labels

examples, example_labels = load_from_file("/FastVideo/examples/inference/gradio/local/prompts_final.txt")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using a hardcoded absolute path /FastVideo/examples/inference/gradio/local/prompts_final.txt will cause the script to fail on any machine where the project is not located at the root of the filesystem. The path should be relative to the script's location to ensure portability.

Suggested change
examples, example_labels = load_from_file("/FastVideo/examples/inference/gradio/local/prompts_final.txt")
script_dir = os.path.dirname(os.path.realpath(__file__))
examples, example_labels = load_from_file(os.path.join(script_dir, "prompts_final.txt"))

Comment on lines +146 to +148
safe_prompt = params.prompt[:100].replace(' ', '_').replace('/', '_').replace('\\', '_')
video_filename = f"{params.prompt[:100]}.mp4"
output_path = os.path.join(output_dir, video_filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are a couple of issues with how the output video path is handled here:

  1. The safe_prompt variable is created but never used. This is dead code.
  2. The video_filename is constructed from the raw prompt, which may contain characters that are invalid in filenames (e.g., /, ?, *). This could cause an error when Gradio tries to serve the file.
  3. This logic does not account for filename collisions. The VideoGenerator handles this by appending suffixes like _1, _2, etc., to the filename if it already exists. Because this script doesn't replicate that logic, it might return a path to an older video if a new video was saved with a different name due to a collision.

A more robust solution would be to have VideoGenerator.generate_video return the final path of the saved video and use that path here. I've added a separate comment in fastvideo/entrypoints/video_generator.py with a suggestion to implement this.

}

def create_timing_display(inference_time, total_time, stage_execution_times, num_frames):
dit_denoising_time = f"{stage_execution_times[5]:.2f}s" if len(stage_execution_times) > 5 else "N/A"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Accessing stage_execution_times[5] with a hardcoded index is brittle. If the order or number of pipeline stages changes in the future, this will either fetch the wrong timing information or cause an IndexError. It would be more robust to find the index of the 'DiT Denoising' stage dynamically from the stage_names list, which is already being retrieved from logging_info.

app,
demo,
path="/gradio",
allowed_paths=[os.path.abspath("outputs"), os.path.abspath("fastvideo-logos")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The path fastvideo-logos in allowed_paths seems incorrect. The logo asset assets/full.svg is used in the Gradio interface, which is located in the assets directory. To allow Gradio to serve this file, you should include the assets directory in allowed_paths.

Suggested change
allowed_paths=[os.path.abspath("outputs"), os.path.abspath("fastvideo-logos")]
allowed_paths=[os.path.abspath("outputs"), os.path.abspath("assets")]

Comment on lines +205 to +207
print(
f"The video name '{os.path.basename(output_path)}' contained invalid characters. It has been renamed to '{video_name}'"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using print() for logging is inconsistent with the rest of the codebase, which uses the logging module. It's better to use logger.info() or logger.warning() for maintainability and to allow for centralized log level control.

Suggested change
print(
f"The video name '{os.path.basename(output_path)}' contained invalid characters. It has been renamed to '{video_name}'"
)
logger.info(
"The video name '%s' contained invalid characters. It has been renamed to '%s'",
os.path.basename(output_path), video_name
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants