Skip to content

fix: video gen chinese char#855

Merged
tastelikefeet merged 1 commit intomodelscope:mainfrom
suluyana:fix/video_chinese_char
Feb 4, 2026
Merged

fix: video gen chinese char#855
tastelikefeet merged 1 commit intomodelscope:mainfrom
suluyana:fix/video_chinese_char

Conversation

@suluyana
Copy link
Copy Markdown
Collaborator

@suluyana suluyana commented Feb 4, 2026

Change Summary

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Run pre-commit install and pre-commit run --all-files before git commit, and passed lint check.
  • Documentation reflects the changes where applicable

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @suluyana, 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 addresses a potential issue with the rendering of Chinese characters during video generation. It enhances the font selection mechanism to ensure that a suitable font capable of displaying Chinese characters is identified and used, thereby improving the robustness and correctness of text rendering in generated videos.

Highlights

  • Improved Chinese Character Font Handling: The get_font method in agent.py has been updated to use fc-match for more reliable font discovery and includes a check to ensure the selected font can render Chinese characters, preventing display issues.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • projects/singularity_cinema/create_background/agent.py
    • The get_font method was refactored to use subprocess.check_output with fc-match for finding font paths, replacing fm.findfont.
    • A validation step was added using font.getmask('中') to confirm that a candidate font can render Chinese characters before it is selected.
    • Logging statements (logger.info, logger.warning, logger.error) were introduced to provide better visibility into the font selection process and any encountered issues.
    • The error handling was improved to catch general Exception during font loading and character mask creation, with a final fallback to ImageFont.load_default() if no suitable Chinese font is found.
Activity
  • The pull request was created by suluyana to fix an issue with Chinese character generation.
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
Copy Markdown
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

The pull request effectively addresses the issue of Chinese character generation by updating the font loading mechanism. The new approach uses fc-match for font discovery and includes a crucial check for Chinese character support. However, it introduces a platform-specific dependency and uses a broad exception catch that could be more precise for better error handling and debugging.

Comment on lines +35 to +36
font_path = subprocess.check_output(
['fc-match', '-f', '%{file}\n', name], text=True).strip()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The use of fc-match introduces a strong dependency on Linux systems with the fontconfig library. This might limit the portability of the application to other operating systems like Windows or macOS where fc-match is not natively available. Consider if this platform-specific tool is universally available in all target deployment environments or if a more cross-platform font discovery method is necessary.

def get_font(self, size):
for font_name in self.fonts:
candidates = list(self.fonts)
import subprocess
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The import subprocess statement should be moved to the top of the file with other module imports. Importing modules inside a function can lead to performance overhead as the module is re-imported every time the function is called. It also improves code readability and organization.

Comment on lines +43 to 45
except Exception as e:
logger.warning(f"Font '{name}' not usable: {e}")
continue
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Catching a general Exception can sometimes mask specific issues, making debugging more challenging. It's generally better to catch more specific exceptions that might be raised by subprocess.check_output (e.g., FileNotFoundError if fc-match is not found, subprocess.CalledProcessError if the command fails) or ImageFont.truetype (e.g., OSError, ValueError). This provides clearer error messages and allows for more targeted error handling if needed.

except (FileNotFoundError, subprocess.CalledProcessError, OSError, ValueError) as e:
                logger.warning(f"Font '{name}' not usable: {e}")
                continue

@tastelikefeet tastelikefeet merged commit 58ff89e into modelscope:main Feb 4, 2026
1 of 2 checks passed
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