Views
No views yet
1
2# pip install git+https://github.com/LLaVA-VL/LLaVA-NeXT.git
3# Replace the corresponding code files in the original repository with those in https://github.com/Flame-Code-VLM/Flame-Code-VLM/tree/main/model
4# export PYTHONPATH="/your_path_to_LLaVA-NeXT_repo:$PYTHONPATH"
5
6from llava.model.builder import load_pretrained_model
7from llava.mm_utils import process_images, tokenizer_image_token
8from llava.constants import DEFAULT_IMAGE_TOKEN
9
10from PIL import Image
11import torch
12import warnings
13
14warnings.filterwarnings("ignore")
15
16pretrained = "Flame-Code-VLM/flame_waterfall_7b"
17
18model_name = "flame"
19device = "cuda"
20device_map = "auto"
21llava_model_args = {
22 "multimodal": True,
23 "attn_implementation": None,
24}
25tokenizer, model, image_processor, max_length = load_pretrained_model(pretrained, None, model_name, device_map=device_map,**llava_model_args)
26model.config.tokenizer_padding_side = 'left' # Use left padding for batch processing
27model.eval()
28
29url = "path_to_your_screenshot_image_file"
30image = Image.open(url)
31image_tensor = process_images([image], image_processor, model.config)
32image_tensor = [_image.to(dtype=torch.float16, device=device) for _image in image_tensor]
33
34prompt = "Below is an image of the page to create. Generate React code and styles to replicate the design, including layout, typography, and styling. Format your response as follows:'// CSS\n[CSS/SCSS code]\n\n// [React Implementation (JS/TS/JSX/TSX)]\n[Component code]'.\n\n ### Input Image:\n{image}\n\n### Response:\n"
35
36input_ids = tokenizer_image_token(prompt, tokenizer, return_tensors='pt')
37input_ids = input_ids.unsqueeze(0)
38input_ids=input_ids.to(device)
39image_sizes = [image.size]
40modalities = ["image"]
41
42cont = model.generate(
43 input_ids,
44 images=image_tensor,
45 image_sizes=image_sizes,
46 modalities=modalities, # Added this line with the modalities
47 do_sample=True,
48 temperature=0.1,
49 max_new_tokens=4096,
50 top_p=0.95,
51 repetition_penalty=1.05
52)
53
54text_outputs = tokenizer.batch_decode(cont, skip_special_tokens=True)
55