Spaces:
Runtime error
Runtime error
ChrisMofus
commited on
Commit
•
eb65490
1
Parent(s):
283cc37
Change model
Browse files- app.py +10 -21
- requirements.txt +3 -2
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
-
import
|
4 |
-
|
5 |
-
from transformers import AutoProcessor, AutoModelForVision2Seq
|
6 |
|
7 |
DEVICE = "cuda:0"
|
8 |
|
@@ -15,22 +14,12 @@ if uploaded_file is not None:
|
|
15 |
image = Image.open(uploaded_file)
|
16 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
prompts = [
|
25 |
-
"Describe the image in a few sentences.",
|
26 |
-
]
|
27 |
-
images = [image]
|
28 |
-
inputs = processor(text=prompts, images=images, padding=True, return_tensors="pt")
|
29 |
-
inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
|
30 |
-
|
31 |
-
|
32 |
-
# Generate
|
33 |
-
generated_ids = model.generate(**inputs, max_new_tokens=500)
|
34 |
-
generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
35 |
|
36 |
-
|
|
|
|
1 |
+
import einops
|
2 |
import streamlit as st
|
3 |
from PIL import Image
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
5 |
|
6 |
DEVICE = "cuda:0"
|
7 |
|
|
|
14 |
image = Image.open(uploaded_file)
|
15 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
16 |
|
17 |
+
model_id = "vikhyatk/moondream2"
|
18 |
+
revision = "2024-05-08"
|
19 |
+
model = AutoModelForCausalLM.from_pretrained(
|
20 |
+
model_id, trust_remote_code=True, revision=revision
|
21 |
+
)
|
22 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
enc_image = model.encode_image(image)
|
25 |
+
print(model.answer_question(enc_image, "Describe this image in a few sentences.", tokenizer))
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
|
|
1 |
streamlit
|
2 |
Pillow
|
3 |
-
|
4 |
-
|
|
|
1 |
+
einops
|
2 |
streamlit
|
3 |
Pillow
|
4 |
+
transformers
|
5 |
+
torch
|