文本生成图像服务

通过优化文本提示并使用指定模型生成图像,同时评估图像的内容一致性和感知质量。

  • by phoenixdna
  • 本地部署
  • 更新于

使用说明

功能描述:

Generate an image from a given text prompt using a specified model, 
then evaluate its quality and relevance.

This function:
1. Improves the input prompt using a Qwen3-based optimizer.
2. Generates an image with the chosen model.
3. Saves the image locally.
4. Evaluates the image on content consistency (SC_Score) and perceptual quality (PQ_Score).
5. Returns image path, filename, scores, evaluation remarks, and logs.

参数:

Args:
    prompt (str): 
        The text description of the image to generate.
    model_name (str): 
        The model used for image generation. 
        Must be one of:
          - "black-forest-labs/FLUX.1-Krea-dev"
          - "Qwen/Qwen-Image"
          - "MusePublic/489_ckpt_FLUX_1"
          - "MusePublic/flux-high-res"
        Defaults to "black-forest-labs/FLUX.1-Krea-dev".

返回:

Returns:
    Tuple[str, str, float, float, str, str, str]: 
        A tuple containing:
        - save_path: Local path to the generated image (or placeholder if failed).
        - fname: The filename of the image, or "Generation failed".
        - sc: SC_Score (content consistency, 0.0–10.0).
        - pq: PQ_Score (perceptual quality, 0.0–10.0).
        - final_prompt: The optimized prompt used for generation.
        - reason: Evaluation remarks or error messages.
        - log_entry: Log entry with summary of results and evaluations.

Notes:
    - If generation fails, a white placeholder image will be saved.
    - Designed for Gradio MCP server (`gr.Image(type="filepath")` compatibility).
    - Scores default to 0.0 if evaluation fails.