root commited on
Commit
be10b16
·
1 Parent(s): aad4eba

readme change

Browse files
Files changed (1) hide show
  1. README.md +75 -0
README.md CHANGED
@@ -1,3 +1,78 @@
1
  ---
 
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ inference: false
3
  license: apache-2.0
4
  ---
5
+
6
+ # Model Card
7
+
8
+ <p align="center">
9
+ <img src="./icon.png" alt="Logo" width="350">
10
+ </p>
11
+
12
+ 📖 [Technical report]() | 🏠 [Code]() | 🐰 [Demo](http://bunny.dataoptim.org/)
13
+ This is Owlet-Phi-2.
14
+
15
+ Owlet is a family of lightweight but powerful multimodal models.
16
+
17
+ We provide Owlet-phi-2, which is built upon [SigLIP](https://huggingface.co/google/siglip-so400m-patch14-384) and [Phi-2](https://huggingface.co/microsoft/phi-2).
18
+
19
+
20
+ # Quickstart
21
+
22
+ Here we show a code snippet to show you how to use the model with transformers.
23
+
24
+ Before running the snippet, you need to install the following dependencies:
25
+
26
+ ```shell
27
+ pip install torch transformers accelerate pillow decord
28
+ ```
29
+
30
+ ```python
31
+ import torch
32
+ import transformers
33
+ from transformers import AutoModelForCausalLM, AutoTokenizer
34
+ from PIL import Image
35
+ import warnings
36
+
37
+
38
+ # disable some warnings
39
+ transformers.logging.set_verbosity_error()
40
+ transformers.logging.disable_progress_bar()
41
+ warnings.filterwarnings('ignore')
42
+
43
+ # set device
44
+ device = 'cuda' # or cpu
45
+ torch.set_default_device(device)
46
+
47
+ # create model
48
+ print('Loading the model...')
49
+ model = AutoModelForCausalLM.from_pretrained(
50
+ 'phronetic-ai/owlet-phi-2',
51
+ torch_dtype=torch.float16, # float32 for cpu
52
+ device_map='auto',
53
+ trust_remote_code=True)
54
+ tokenizer = AutoTokenizer.from_pretrained(
55
+ 'phronetic-ai/owlet-phi-2',
56
+ trust_remote_code=True)
57
+
58
+ print('Model loaded. Processing the query...')
59
+ # text prompt
60
+ prompt = 'What is happening in the video?'
61
+ text = f"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\n{prompt} ASSISTANT:"
62
+ text_chunks = [tokenizer(chunk).input_ids for chunk in text.split('<image>')]
63
+ input_ids = torch.tensor(text_chunks[0] + [-200] + text_chunks[1], dtype=torch.long).unsqueeze(0).to(device)
64
+
65
+ # image or video file path
66
+ file_path = 'sample.mp4'
67
+ input_tensor = model.process(file_path, model.config).to(model.device, dtype=model.dtype)
68
+
69
+ # generate
70
+ output_ids = model.generate(
71
+ input_ids,
72
+ images=input_tensor,
73
+ max_new_tokens=100,
74
+ use_cache=True)[0]
75
+
76
+ print(f'Response: {tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()}')
77
+
78
+ ```