RPW commited on
Commit
e7993e4
·
verified ·
1 Parent(s): 37c32fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,5 +1,6 @@
1
- from transformers import RobertaTokenizer, RobertaForSequenceClassification
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 = RobertaTokenizer.from_pretrained(MODEL_NAME)
11
- model = RobertaForSequenceClassification.from_pretrained(MODEL_NAME).to(device)
 
 
 
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").to("cuda")
 
19
 
20
  text_streamer = TextStreamer(tokenizer, skip_prompt=True)
21
- _ = model.generate(**inputs, streamer=text_streamer, max_new_tokens=128,
22
- use_cache=True, temperature=1.5, min_p=0.1)
 
 
 
 
 
 
 
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
+ )