MCPcopy Create free account
hub / github.com/MeiGen-AI/PosterCraft / PosterGenerator

Class PosterGenerator

inference.py:96–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94
95
96class PosterGenerator:
97 def __init__(self,
98 pipeline_path="black-forest-labs/FLUX.1-dev",
99 custom_transformer_path=None,
100 qwen_model_path=None,
101 device="cuda:0"):
102
103 self.device = torch.device(device) if isinstance(device, str) else device
104
105 # Load Qwen model for prompt rewriting
106 if qwen_model_path and os.path.exists(qwen_model_path):
107 print(f"Loading Qwen model from: {qwen_model_path}")
108 self.qwen_agent = QwenRecapAgent(qwen_model_path, device=self.device)
109 else:
110 self.qwen_agent = None
111
112 # Load Flux pipeline
113 print(f"Loading Flux pipeline from: {pipeline_path}")
114 self.pipeline = FluxPipeline.from_pretrained(pipeline_path, torch_dtype=torch.bfloat16)
115
116 # Load custom transformer if provided
117 if custom_transformer_path:
118 print(f"Loading custom transformer from: {custom_transformer_path}")
119 self.pipeline.transformer = FluxTransformer2DModel.from_pretrained(
120 custom_transformer_path,
121 torch_dtype=torch.bfloat16
122 )
123
124 self.pipeline.to(self.device)
125
126 def generate(self,
127 prompt,
128 enable_recap=True,
129 width=832,
130 height=1216,
131 num_inference_steps=28,
132 guidance_scale=3.5,
133 seed=None):
134
135 # Prompt rewriting
136 if enable_recap and self.qwen_agent:
137 final_prompt = self.qwen_agent.recap_prompt(prompt)
138 else:
139 final_prompt = prompt
140
141 # Poster generation
142 if seed is None:
143 seed = random.randint(1, 2**32 - 1)
144
145 generator = torch.Generator(device=self.device).manual_seed(seed)
146
147 with torch.inference_mode():
148 image = self.pipeline(
149 prompt=final_prompt,
150 generator=generator,
151 num_inference_steps=num_inference_steps,
152 guidance_scale=guidance_scale,
153 width=width,

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected