Align-Anything
Collection
10 items
β’
Updated
β’
3
This repository contains a version of the LLaVA model that supports image and audio input from the Llama 3.1-8B foundation model using the PKU-Alignment/align-anything library.
from align_anything.models.llama_vision_audio_model import (
LlamaVisionAudioForConditionalGeneration,
LlamaVisionAudioProcessor,
)
import torch
import torchaudio
from PIL import Image
path = <path_to_model_dir>
processor = LlamaVisionAudioProcessor.from_pretrained(path)
model = LlamaVisionAudioForConditionalGeneration.from_pretrained(path)
prompt = "<|start_header_id|>user<|end_header_id|>: Where is the capital of China?\n<|start_header_id|>assistant<|end_header_id|>: "
inputs = processor(text=prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=1024)
print(processor.decode(outputs[0], skip_special_tokens=True))
prompt = "<|start_header_id|>user<|end_header_id|>: Summarize the audio's contents.<audio>\n<|start_header_id|>assistant<|end_header_id|>: "
audio_path = "align-anything/assets/test_audio.wav"
audio, _ = torchaudio.load(audio_path)
if audio.shape[0] == 2:
audio = audio.mean(dim=0, keepdim=True)
audio = audio.squeeze().tolist()
inputs = processor(text=prompt, raw_speech=audio, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=1024)
print(processor.decode(outputs[0], skip_special_tokens=False))
prompt = "<|start_header_id|>user<|end_header_id|>: <image> Give an overview of what's in the image.\n<|start_header_id|>assistant<|end_header_id|>: "
image_path = "align-anything/assets/test_image.webp"
image = Image.open(image_path)
inputs = processor(text=prompt, images=image, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=1024)
print(processor.decode(outputs[0], skip_special_tokens=True))
Base model
meta-llama/Llama-3.1-8B