Update README.md
Browse files
README.md
CHANGED
@@ -74,7 +74,7 @@ $ pip install git+https://github.com/huggingface/transformers
|
|
74 |
|
75 |
Then, copy the snippet from the section that is relevant for your use case.
|
76 |
|
77 |
-
#### Running the model
|
78 |
|
79 |
```python
|
80 |
from transformers import AutoProcessor, AutoModel
|
@@ -117,6 +117,41 @@ print(response)
|
|
117 |
```
|
118 |
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
## Evaluation
|
121 |
|
122 |
Model evaluation metrics and results.
|
|
|
74 |
|
75 |
Then, copy the snippet from the section that is relevant for your use case.
|
76 |
|
77 |
+
#### Running the model with chat_template
|
78 |
|
79 |
```python
|
80 |
from transformers import AutoProcessor, AutoModel
|
|
|
117 |
```
|
118 |
|
119 |
|
120 |
+
#### Running the model with local data
|
121 |
+
|
122 |
+
```python
|
123 |
+
from io import BytesIO
|
124 |
+
from urllib.request import urlopen
|
125 |
+
import soundfile
|
126 |
+
from PIL import Image
|
127 |
+
|
128 |
+
|
129 |
+
# get Audio data from URL
|
130 |
+
url = "https://huggingface.co/microsoft/Phi-4-multimodal-instruct/resolve/main/examples/what_is_shown_in_this_image.wav"
|
131 |
+
audio, sr = soundfile.read(BytesIO(urlopen(url).read()))
|
132 |
+
audio_token = '<start_of_audio>'
|
133 |
+
|
134 |
+
|
135 |
+
messages = [
|
136 |
+
{'role': 'user', 'content': audio_token + 'Translate this audio into Korean.'},
|
137 |
+
]
|
138 |
+
|
139 |
+
prompt = processor.tokenizer.apply_chat_template(
|
140 |
+
messages, tokenize=False, add_generation_prompt=True
|
141 |
+
)
|
142 |
+
|
143 |
+
|
144 |
+
inputs = processor(text=prompt, audio=[audio], add_special_tokens=False, return_tensors="pt")
|
145 |
+
|
146 |
+
with torch.inference_mode():
|
147 |
+
generate_ids = model.generate(**inputs, max_new_tokens=128, do_sample=False)
|
148 |
+
generate_ids = generate_ids[:, inputs['input_ids'].shape[1] :]
|
149 |
+
response = processor.batch_decode(
|
150 |
+
generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
151 |
+
)[0]
|
152 |
+
print(response)
|
153 |
+
```
|
154 |
+
|
155 |
## Evaluation
|
156 |
|
157 |
Model evaluation metrics and results.
|