Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
from transformers import MllamaForConditionalGeneration, AutoProcessor
|
5 |
+
|
6 |
+
model_id = "meta-llama/Llama-3.2-11B-Vision"
|
7 |
+
|
8 |
+
model = MllamaForConditionalGeneration.from_pretrained(
|
9 |
+
model_id,
|
10 |
+
torch_dtype=torch.bfloat16,
|
11 |
+
device_map="auto",
|
12 |
+
)
|
13 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
14 |
+
|
15 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"
|
16 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
17 |
+
|
18 |
+
prompt = "<|image|><|begin_of_text|>If I had to write a haiku for this one"
|
19 |
+
inputs = processor(image, prompt, return_tensors="pt").to(model.device)
|
20 |
+
|
21 |
+
output = model.generate(**inputs, max_new_tokens=30)
|
22 |
+
print(processor.decode(output[0]))
|