Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
-
from transformers import
|
2 |
import torch
|
|
|
3 |
# Define the model path
|
4 |
MODEL_NAME = "RPW/NIH-1.2_Llama-3.2-11B-Vision-Instruct"
|
5 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
@@ -7,16 +8,26 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
7 |
instruction = "You are an expert radiographer. Describe accurately what you see in this image."
|
8 |
|
9 |
# Load the tokenizer and model
|
10 |
-
tokenizer =
|
11 |
-
model =
|
|
|
|
|
|
|
12 |
|
13 |
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
|
14 |
inputs = tokenizer(
|
15 |
image,
|
16 |
input_text,
|
17 |
add_special_tokens=False,
|
18 |
-
return_tensors="pt"
|
|
|
19 |
|
20 |
text_streamer = TextStreamer(tokenizer, skip_prompt=True)
|
21 |
-
_ = model.generate(
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
import torch
|
3 |
+
|
4 |
# Define the model path
|
5 |
MODEL_NAME = "RPW/NIH-1.2_Llama-3.2-11B-Vision-Instruct"
|
6 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
8 |
instruction = "You are an expert radiographer. Describe accurately what you see in this image."
|
9 |
|
10 |
# Load the tokenizer and model
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
12 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME).to(device)
|
13 |
+
|
14 |
+
# Example of messages
|
15 |
+
messages = [{"role": "system", "content": instruction}]
|
16 |
|
17 |
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
|
18 |
inputs = tokenizer(
|
19 |
image,
|
20 |
input_text,
|
21 |
add_special_tokens=False,
|
22 |
+
return_tensors="pt"
|
23 |
+
).to(device)
|
24 |
|
25 |
text_streamer = TextStreamer(tokenizer, skip_prompt=True)
|
26 |
+
_ = model.generate(
|
27 |
+
**inputs,
|
28 |
+
streamer=text_streamer,
|
29 |
+
max_new_tokens=128,
|
30 |
+
use_cache=True,
|
31 |
+
temperature=1.5,
|
32 |
+
min_p=0.1
|
33 |
+
)
|