Views
No views yet
1from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
2import torch
3
4model = Qwen3VLForConditionalGeneration.from_pretrained("deepglugs/qwen3-vl-flux2-8b", torch_dtype=torch.bfloat16, device_map="auto")
5processor = AutoProcessor.from_pretrained("deepglugs/qwen3-vl-flux2-8b")
6# ... your inference code
7# Load your image
8image_path = "path/to/your/image.png"
9image = Image.open(image_path).convert("RGB")
10
11# Use the special flux.2 prompt
12messages = [
13 {
14 "role": "user",
15 "content": [
16 {"type": "image"},
17 {"type": "text", "text": "Describe this image in the flux.2 JSON format."}
18 ]
19 }
20]
21
22text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
23inputs = processor(text=[text], images=[image], return_tensors="pt").to("cuda")
24
25# Generate (use temperature for slight variation if desired)
26generated_ids = model.generate(
27 **inputs,
28 max_new_tokens=1024,
29 do_sample=True,
30 temperature=0.7,
31 top_p=0.9,
32)
33generated_text = processor.batch_decode(generated_ids[:, inputs.input_ids.shape[-1]:], skip_special_tokens=True)[0]
34
35# Parse and pretty-print the JSON output
36try:
37 json_output = json.loads(generated_text)
38 print(json.dumps(json_output, indent=2))
39except json.JSONDecodeError:
40 print("Raw output (JSON parsing failed):")
41 print(generated_text)