Spaces:
Running
Running
greencatted
commited on
Commit
•
0bef8ce
1
Parent(s):
4a41b58
Use Llama Vision Instruct
Browse files
app.py
CHANGED
@@ -1,20 +1,37 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
enable = st.checkbox("Enable camera")
|
10 |
picture = st.camera_input("Take a picture", disabled=not enable)
|
11 |
|
12 |
if picture:
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
|
4 |
+
import torch
|
5 |
+
from transformers import MllamaForConditionalGeneration, AutoProcessor
|
6 |
|
7 |
+
model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
8 |
+
|
9 |
+
model = MllamaForConditionalGeneration.from_pretrained(
|
10 |
+
model_id,
|
11 |
+
torch_dtype=torch.bfloat16,
|
12 |
+
device_map="auto",
|
13 |
+
)
|
14 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
15 |
|
16 |
enable = st.checkbox("Enable camera")
|
17 |
picture = st.camera_input("Take a picture", disabled=not enable)
|
18 |
|
19 |
if picture:
|
20 |
+
image = Image.open(picture)
|
21 |
|
22 |
+
messages = [
|
23 |
+
{"role": "user", "content": [
|
24 |
+
{"type": "image"},
|
25 |
+
{"type": "text", "text": "Provide your best guess as to where this person is holding his online meeting. Just state your guess of location in your response."}
|
26 |
+
]}
|
27 |
+
]
|
28 |
+
input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
|
29 |
+
inputs = processor(
|
30 |
+
image,
|
31 |
+
input_text,
|
32 |
+
add_special_tokens=False,
|
33 |
+
return_tensors="pt"
|
34 |
+
).to(model.device)
|
35 |
|
36 |
+
output = model.generate(**inputs, max_new_tokens=30)
|
37 |
+
print(processor.decode(output[0]))
|