Update README.md
Browse files
README.md
CHANGED
@@ -65,105 +65,77 @@ We, the Bllossom team, are pleased to announce the release of Bllossom-Vision, a
|
|
65 |
### Colab Tutorial
|
66 |
- [Inference-Code-Link](Inference code coming soon)
|
67 |
|
68 |
-
###
|
69 |
-
```bash
|
70 |
-
pip install torch transformers==4.44.0
|
71 |
-
```
|
72 |
-
|
73 |
-
### Python code without Image
|
74 |
```python
|
75 |
-
from transformers import
|
76 |
import torch
|
|
|
|
|
77 |
|
78 |
-
model =
|
79 |
-
'Bllossom/llama-3.
|
80 |
torch_dtype=torch.bfloat16,
|
81 |
device_map='auto'
|
82 |
)
|
83 |
-
processor =
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
bos_token = processor.tokenizer.bos_token_id
|
107 |
-
chat_messages = torch.cat([torch.tensor([[bos_token]]),chat_messages],dim=-1).to(model.device)
|
108 |
-
|
109 |
-
|
110 |
-
output = model.generate(
|
111 |
-
input_ids = chat_messages,
|
112 |
-
use_cache=False,
|
113 |
-
max_new_tokens=2048,
|
114 |
-
top_p=0.9,
|
115 |
-
temperature=0.6,
|
116 |
-
do_sample=True,
|
117 |
-
)
|
118 |
-
|
119 |
-
print(processor.tokenizer.decode(output[0]))
|
120 |
```
|
121 |
|
122 |
-
### Python code
|
123 |
```python
|
124 |
-
from
|
125 |
-
from transformers import LlavaNextForConditionalGeneration,LlavaNextProcessor
|
126 |
import torch
|
|
|
|
|
127 |
|
128 |
-
model =
|
129 |
-
'Bllossom/llama-3.
|
130 |
torch_dtype=torch.bfloat16,
|
131 |
device_map='auto'
|
132 |
)
|
133 |
-
processor =
|
134 |
-
|
135 |
-
image = Image.open('[IMAGE_PATH]').convert('RGB')
|
136 |
-
|
137 |
-
PROMPT=\
|
138 |
-
"""You are a versatile AI assistant named Bllava, capable of both understanding and generating text as well as interpreting and analyzing images. Your role is to kindly and effectively answer the user’s questions, whether they are about text or images, and provide appropriate and helpful responses to all types of queries.
|
139 |
-
|
140 |
-
당신은 텍스트를 이해하고 생성하는 것뿐만 아니라 이미지를 해석하고 분석할 수 있는 다재다능한 AI 어시스턴트 블라바입니다. 사용자의 질문이 텍스트에 관한 것이든 이미지에 관한 것이든 친절하고 효과적으로 답변하며, 모든 유형의 질의에 대해 적절하고 유용한 응답을 제공하는 것이 당신의 역할입니다."""
|
141 |
|
|
|
|
|
142 |
|
143 |
-
instruction = '이미지에 대해서 설명해주세요.'
|
144 |
messages = [
|
145 |
-
|
146 |
-
{'
|
147 |
-
]
|
148 |
-
|
149 |
-
chat_messages = processor.tokenizer.apply_chat_template(
|
150 |
-
messages,
|
151 |
-
tokenize=False,
|
152 |
-
add_generation_prompt=True
|
153 |
-
).to(model.device)
|
154 |
|
155 |
-
|
156 |
-
chat_messages,
|
157 |
-
image,
|
158 |
-
return_tensors='pt',
|
159 |
-
)
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
|
|
165 |
|
166 |
-
|
|
|
167 |
```
|
168 |
|
169 |
|
|
|
65 |
### Colab Tutorial
|
66 |
- [Inference-Code-Link](Inference code coming soon)
|
67 |
|
68 |
+
### Python code (Use Vision-language Model)
|
|
|
|
|
|
|
|
|
|
|
69 |
```python
|
70 |
+
from transformers import MllamaForConditionalGeneration,MllamaProcessor
|
71 |
import torch
|
72 |
+
from PIL import Image
|
73 |
+
import requests
|
74 |
|
75 |
+
model = MllamaForConditionalGeneration.from_pretrained(
|
76 |
+
'Bllossom/llama-3.2-Korean-Bllossom-AICA-5.2B',
|
77 |
torch_dtype=torch.bfloat16,
|
78 |
device_map='auto'
|
79 |
)
|
80 |
+
processor = MllamaProcessor.from_pretrained('Bllossom/llama-3.2-Korean-Bllossom-AICA-5.2B')
|
81 |
+
|
82 |
+
url = "https://t1.daumcdn.net/cfile/tistory/21527E4A543DCABE1D"
|
83 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
84 |
+
|
85 |
+
messages = [
|
86 |
+
{'role': 'user','content': [
|
87 |
+
{'type':'image'}
|
88 |
+
{'type': 'text','text': '이 문서를 마크다운으로 바꿔줘'}
|
89 |
+
]},
|
90 |
+
]
|
91 |
+
|
92 |
+
input_text = processor.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)
|
93 |
+
|
94 |
+
inputs = processor(
|
95 |
+
image,
|
96 |
+
input_text,
|
97 |
+
add_special_tokens=False,
|
98 |
+
return_tensors="pt",
|
99 |
+
).to(model.device)
|
100 |
+
|
101 |
+
output = model.generate(**inputs, max_new_tokens=256,temperature=0.1,eos_token_id=processor.tokenizer.convert_tokens_to_ids('<|eot_id|>'),use_cache=False)
|
102 |
+
print(processor.decode(output[0]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
```
|
104 |
|
105 |
+
### Python code (Use Language Model)
|
106 |
```python
|
107 |
+
from transformers import MllamaForConditionalGeneration,MllamaProcessor
|
|
|
108 |
import torch
|
109 |
+
from PIL import Image
|
110 |
+
import requests
|
111 |
|
112 |
+
model = MllamaForConditionalGeneration.from_pretrained(
|
113 |
+
'Bllossom/llama-3.2-Korean-Bllossom-AICA-5.2B',
|
114 |
torch_dtype=torch.bfloat16,
|
115 |
device_map='auto'
|
116 |
)
|
117 |
+
processor = MllamaProcessor.from_pretrained('Bllossom/llama-3.2-Korean-Bllossom-AICA-5.2B')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
+
url = "https://cdn.discordapp.com/attachments/1156141391798345742/1313407928287494164/E18489E185B3E1848FE185B3E18485E185B5E186ABE18489E185A3E186BA202021-11-1620E1848BE185A9E18492E185AE2011.png?ex=675005f4&is=674eb474&hm=fc9c4231203f53c27f6edd2420961c182dd4a1ed14d4b73e04127f11393729af&"
|
120 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
121 |
|
|
|
122 |
messages = [
|
123 |
+
{'role': 'user','content': [
|
124 |
+
{'type': 'text','text': '자연어처리 15주치 커리큘럼을 짜줘'}
|
125 |
+
]},
|
126 |
+
]
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
+
input_text = processor.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)
|
|
|
|
|
|
|
|
|
129 |
|
130 |
+
inputs = processor(
|
131 |
+
images=None,
|
132 |
+
text=input_text,
|
133 |
+
add_special_tokens=False,
|
134 |
+
return_tensors="pt",
|
135 |
+
).to(model.device)
|
136 |
|
137 |
+
output = model.generate(**inputs,max_new_tokens=256,temperature=0.1,eos_token_id=processor.tokenizer.convert_tokens_to_ids('<|eot_id|>'),use_cache=False)
|
138 |
+
print(processor.decode(output[0]))
|
139 |
```
|
140 |
|
141 |
|