kirchik47 commited on
Commit
6c250d4
·
1 Parent(s): a6f8b18

Deleted main for Qwen, config modifications

Browse files
custom_got/{model_config.json → config.json} RENAMED
File without changes
main.py DELETED
@@ -1,47 +0,0 @@
1
- from transformers import AutoModel, AutoTokenizer
2
- import torch
3
- from byaldi.RAGModel import RAGMultiModalModel
4
- from byaldi.colpali import ColPaliModel
5
- from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
6
- from qwen_vl_utils import process_vision_info
7
- import torch
8
- from PIL import Image
9
- import numpy as np
10
-
11
-
12
- colpali_model = ColPaliModel.from_pretrained('vidore/colpali')
13
- print(colpali_model.doc_id_to_metadata)
14
- model = Qwen2VLForConditionalGeneration.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", torch_dtype=torch.bfloat16).eval()
15
- processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", trust_remote_code=True)
16
- messages = [
17
- {
18
- "role": "user",
19
- "content": [
20
- {
21
- "type": "image",
22
- "image": Image.open('template.jpg'),
23
- },
24
- {"type": "text", "text": 'Return full text of the document as a plain text'},
25
- ],
26
- }
27
- ]
28
-
29
- text = processor.apply_chat_template(
30
- messages, tokenize=False, add_generation_prompt=True
31
- )
32
- img = Image.open('docs/hindi_template.jpg')
33
- inputs = processor(
34
- text=text,
35
- images=img,
36
- padding=True,
37
- return_tensors="pt",
38
- )
39
- inputs = inputs.to("cpu")
40
- generated_ids = model.generate(**inputs, max_new_tokens=5000)
41
- generated_ids_trimmed = [
42
- out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
43
- ]
44
- output_text = processor.batch_decode(
45
- generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
46
- )
47
- print(output_text)