liuyashu002
commited on
Commit
·
15b04bf
1
Parent(s):
ffa9921
readme update
Browse files
README.md
CHANGED
@@ -1,3 +1,69 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
---
|
4 |
+
We have open-sourced Flame-Waterfall-7B, a model built by connecting DeepSeek-Coder-7B-Instruct and the SigLIP vision encoder with a 2-layer MLP, and instruction-tuned on the Flame-Code-VLM/Flame-Waterfall-React dataset.
|
5 |
+
This model is released to showcase the value of the synthesized dataset. However, it is not intended for general-purpose tasks. Please use it with caution.
|
6 |
+
|
7 |
+
|
8 |
+
### Generation
|
9 |
+
|
10 |
+
The following is the sample code for inference.
|
11 |
+
|
12 |
+
```python
|
13 |
+
|
14 |
+
# pip install git+https://github.com/LLaVA-VL/LLaVA-NeXT.git
|
15 |
+
# Replace the corresponding code files in the original repository with those in https://github.com/Flame-Code-VLM/Flame-Code-VLM/tree/main/model
|
16 |
+
# export PYTHONPATH="/your_path_to_LLaVA-NeXT_repo:$PYTHONPATH"
|
17 |
+
|
18 |
+
from llava.model.builder import load_pretrained_model
|
19 |
+
from llava.mm_utils import process_images, tokenizer_image_token
|
20 |
+
from llava.constants import DEFAULT_IMAGE_TOKEN
|
21 |
+
|
22 |
+
from PIL import Image
|
23 |
+
import torch
|
24 |
+
import warnings
|
25 |
+
|
26 |
+
warnings.filterwarnings("ignore")
|
27 |
+
|
28 |
+
pretrained = "Flame-Code-VLM/flame_waterfall_7b"
|
29 |
+
|
30 |
+
model_name = "flame"
|
31 |
+
device = "cuda"
|
32 |
+
device_map = "auto"
|
33 |
+
llava_model_args = {
|
34 |
+
"multimodal": True,
|
35 |
+
"attn_implementation": None,
|
36 |
+
}
|
37 |
+
tokenizer, model, image_processor, max_length = load_pretrained_model(pretrained, None, model_name, device_map=device_map,**llava_model_args)
|
38 |
+
model.config.tokenizer_padding_side = 'left' # Use left padding for batch processing
|
39 |
+
model.eval()
|
40 |
+
|
41 |
+
url = "path_to_your_screenshot_image_file"
|
42 |
+
image = Image.open(url)
|
43 |
+
image_tensor = process_images([image], image_processor, model.config)
|
44 |
+
image_tensor = [_image.to(dtype=torch.float16, device=device) for _image in image_tensor]
|
45 |
+
|
46 |
+
prompt = "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"
|
47 |
+
|
48 |
+
input_ids = tokenizer_image_token(prompt, tokenizer, return_tensors='pt')
|
49 |
+
input_ids = input_ids.unsqueeze(0)
|
50 |
+
input_ids=input_ids.to(device)
|
51 |
+
image_sizes = [image.size]
|
52 |
+
modalities = ["image"]
|
53 |
+
|
54 |
+
cont = model.generate(
|
55 |
+
input_ids,
|
56 |
+
images=image_tensor,
|
57 |
+
image_sizes=image_sizes,
|
58 |
+
modalities=modalities, # Added this line with the modalities
|
59 |
+
do_sample=True,
|
60 |
+
num_beams=5,
|
61 |
+
temperature=0.1,
|
62 |
+
max_new_tokens=4096,
|
63 |
+
top_p=0.95,
|
64 |
+
repetition_penalty=1.05
|
65 |
+
)
|
66 |
+
|
67 |
+
text_outputs = tokenizer.batch_decode(cont, skip_special_tokens=True)
|
68 |
+
|
69 |
+
```
|