Skip to content

Hunyuan-PromptEnhancer/PromptEnhancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PromptEnhancer: A Simple Approach to Enhance Text-to-Image Models via Chain-of-Thought Prompt Rewriting

Linqing Wang · Ximing Xing · Yiji Cheng · Zhiyuan Zhao · Jiale Tao · QiXun Wang · Ruihuang Li · Comi Chen · Xin Li · Mingrui Wu · Xinchi Deng · Chunyu Wang · Qinglin Lu*

Tencent Hunyuan

Project Lead · *Corresponding Author

arXiv Zhihu HuggingFace Model Homepage HunyuanImage2.1 Code HunyuanImage2.1 Model Python Transformers PyTorch


PromptEnhancer Teaser

Overview

Hunyuan-PromptEnhancer is a prompt rewriting utility built on top of Tencent's Hunyuan models. It restructures an input prompt while preserving the original intent, producing clearer, layered, and logically consistent prompts suitable for downstream image generation or similar tasks.

  • Preserves intent across key elements (subject/action/quantity/style/layout/relations/attributes/text, etc.).
  • Encourages a "global–details–summary" narrative, describing primary elements first, then secondary/background elements, ending with a concise style/type summary.
  • Robust output parsing with graceful fallback: prioritizes <answer>...</answer>; if missing, removes <think>...</think> and extracts clean text; otherwise falls back to the original input.
  • Configurable inference parameters (temperature, top_p, max_new_tokens) for balancing determinism and diversity.

Installation

pip install -r requirements.txt

Model Download

huggingface-cli download tencent/HunyuanImage-2.1/reprompt --local-dir ./models/

Quickstart

from inference.prompt_enhancer import HunyuanPromptEnhancer

# 1) Provide a local path or a repo id, e.g., "tencent/Hunyuan-7B-Instruct"
models_root_path = "./models/"

# 2) Initialize (device_map respects your configuration)
enhancer = HunyuanPromptEnhancer(models_root_path=models_root_path, device_map="auto")

# 3) Enhance a prompt (Chinese or English)
user_prompt = "Third-person view, a race car speeding on a city track..."
new_prompt = enhancer.predict(
    prompt_cot=user_prompt,
    # Default system prompt is tailored for image prompt rewriting; override if needed
    temperature=0.7,   # >0 enables sampling; 0 uses deterministic generation
    top_p=0.9,
    max_new_tokens=256,
)

print("Enhanced:", new_prompt)

Parameters

  • models_root_path: Local path or repo id; supports trust_remote_code models.
  • device_map: Device mapping (default auto).
  • predict(...):
    • prompt_cot (str): Input prompt to rewrite.
    • sys_prompt (str): Optional system prompt; a default is provided for image prompt rewriting.
    • temperature (float): >0 enables sampling; 0 for deterministic generation.
    • top_p (float): Nucleus sampling threshold (effective when sampling).
    • max_new_tokens (int): Maximum number of new tokens to generate.

TODO

  • open source PromptEnhancerV2-32B model

License

This project is distributed under the terms specified in LICENSE.

Citation

If you find this project useful, please consider citing:

@article{promptenhancer,
  title={PromptEnhancer: A Simple Approach to Enhance Text-to-Image Models via Chain-of-Thought Prompt Rewriting},
  author={Wang, Linqing and Xing, Ximing and Cheng, Yiji and Zhao, Zhiyuan and Tao, Jiale and Wang, QiXun and Li, Ruihuang and Chen, Comi and Li, Xin and Wu, Mingrui and Deng, Xinchi and Wang, Chunyu and Lu, Qinglin},
  journal={arXiv preprint arXiv:2509.04545},
  year={2025}
}

Acknowledgements

We would like to thank the following open-source projects and communities for their contributions to open research and exploration: Transformers and HuggingFace.

Contact

If you would like to leave a message for our R&D and product teams, Welcome to contact our open-source team . You can also contact us via email (hunyuan_opensource@tencent.com).

About

PromptEnhancer is a prompt-rewriting tool, refining prompts into clearer, structured versions for better image generation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages