MCPcopy Create free account
hub / github.com/ResearAI/AutoFigure / convert_code_to_text2image_prompt

Function convert_code_to_text2image_prompt

autofigure/enhancer.py:25–225  ·  view source on GitHub ↗

Convert code (mxgraphxml, HTML, etc.) to text2image prompt using LLM. This function uses an LLM to analyze the given code and generate a detailed prompt that can be used for image generation/enhancement. Args: source_code: The source code to convert art_style: Art

(
    source_code: str,
    art_style: str = "",
    content_type: str = "paper",
    code_format: str = "mxgraphxml",
    api_key: str = "",
    base_url: str = "",
    model: str = "",
    provider: str = "bianxie",
)

Source from the content-addressed store, hash-verified

23
24
25def convert_code_to_text2image_prompt(
26 source_code: str,
27 art_style: str = "",
28 content_type: str = "paper",
29 code_format: str = "mxgraphxml",
30 api_key: str = "",
31 base_url: str = "",
32 model: str = "",
33 provider: str = "bianxie",
34) -> Optional[str]:
35 """
36 Convert code (mxgraphxml, HTML, etc.) to text2image prompt using LLM.
37
38 This function uses an LLM to analyze the given code and generate a detailed
39 prompt that can be used for image generation/enhancement.
40
41 Args:
42 source_code: The source code to convert
43 art_style: Art style to apply in the generated prompt
44 content_type: Type of content ('paper', 'survey', 'blog', 'textbook')
45 code_format: Format of the code ('mxgraphxml', 'html', 'pptx')
46 api_key: API key for the LLM provider
47 base_url: Base URL for the API endpoint
48 model: Model name to use
49 provider: Provider name (bianxie, openrouter, gemini)
50
51 Returns:
52 Text2image prompt string, or None on failure
53 """
54 try:
55 from openai import OpenAI
56
57 if not api_key:
58 print("[Code2Prompt] ERROR: API key not provided!")
59 return None
60
61 print(f"[Code2Prompt] Converting {code_format.upper()} to image prompt...")
62 print(f"[Code2Prompt] Art style: {art_style or '(default)'}")
63 print(f"[Code2Prompt] Code length: {len(source_code)} chars")
64
65 format_descriptions = {
66 'pptx': 'Python-PPTX code that generates PowerPoint presentation slides',
67 'html': 'HTML/CSS/JavaScript code that creates web-based visualizations',
68 'mxgraphxml': 'mxGraph XML code (draw.io/diagrams.net format) that defines diagram layouts with shapes, connectors, and placeholder icons',
69 'svg': 'SVG code that defines vector graphics'
70 }
71
72 format_specific_instructions = {
73 'pptx': """
74**PPTX CODE ANALYSIS FOCUS:**
75- Analyze the PowerPoint slide structure and layout
76- Identify text boxes, shapes, and visual elements
77- Extract positioning information (coordinates, dimensions)
78- Understand the presentation flow and hierarchy
79- Convert programmatic slide creation into visual descriptions
80""",
81 'html': """
82**HTML CODE ANALYSIS FOCUS:**

Callers 1

_run_enhancementFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected