manifestasi commited on
Commit
5a0e59f
·
verified ·
1 Parent(s): 4a78666

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +69 -0
README.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ pipeline_tag: image-text-to-text
6
+ ---
7
+ # This Model is for Educational Research Purpose Only.
8
+
9
+ # Sample Code
10
+
11
+ ```
12
+ %%capture
13
+ !pip install -U bitsandbytes
14
+
15
+ from transformers import AutoProcessor, AutoModelForVision2Seq
16
+ import torch
17
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
18
+
19
+ processor = AutoProcessor.from_pretrained("manifestasi/smolVLM-161M-q4-manifestasi")
20
+ model = AutoModelForVision2Seq.from_pretrained("manifestasi/smolVLM-161M-q4-manifestasi",
21
+ torch_dtype=torch.float16,
22
+ _attn_implementation="eager").to(DEVICE)
23
+
24
+ from PIL import Image
25
+ from transformers.image_utils import load_image
26
+
27
+
28
+ # Load images
29
+ # image1 = load_image("https://huggingface.co/spaces/HuggingFaceTB/SmolVLM/resolve/main/example_images/rococo.jpg")
30
+ image2 = load_image("/kaggle/input/bandaraaa/799269_1200.jpg")
31
+
32
+ # Create input messages
33
+ messages = [
34
+ {
35
+ "role": "user",
36
+ "content": [
37
+ # {"type": "image"},
38
+ {"type": "image"},
39
+ {"type": "text",
40
+ "text": """
41
+ Instructions :
42
+ you are visual assistant for blind people, please answer politely and short
43
+ under 100 words.
44
+ Prompt :
45
+ can you direct me to find toilet
46
+ """}
47
+ ]
48
+ },
49
+ ]
50
+
51
+ # Prepare inputs
52
+ prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
53
+ # inputs = processor(text=prompt, return_tensors="pt")
54
+ inputs = processor(text=prompt, images=[image2], return_tensors="pt")
55
+ inputs = inputs.to(DEVICE)
56
+ # Generate outputs
57
+ from time import time
58
+
59
+ tim1 = time()
60
+ generated_ids = model.generate(**inputs, max_new_tokens=120)
61
+ generated_texts = processor.batch_decode(
62
+ generated_ids,
63
+ skip_special_tokens=True,
64
+ )
65
+ tim2 = time()
66
+ print(f"{(tim2 - tim1)} detik")
67
+ print(generated_texts[0].split("Assistant: ")[1])
68
+
69
+ ```