ManishThota commited on
Commit
420cfad
1 Parent(s): 1e8fcbf

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +18 -14
README.md CHANGED
@@ -43,18 +43,22 @@ model = AutoModelForCausalLM.from_pretrained(
43
  trust_remote_code=True)
44
  tokenizer = AutoTokenizer.from_pretrained("ManishThota/Sparrow", trust_remote_code=True)
45
 
46
- #Set inputs
47
- text = "A chat between a curious user and an artificial intelligence assistant. USER: <image>\nCan you explain the slide? ASSISTANT:"
48
- image = Image.open("images/week_02_page_02")
49
-
50
- input_ids = tokenizer(text, return_tensors='pt').input_ids
51
- image_tensor = model.image_preprocess(image)
52
-
53
- #Generate the answer
54
- output_ids = model.generate(
55
- input_ids,
56
- max_new_tokens=1500,
57
- images=image_tensor,
58
- use_cache=True)[0]
59
- print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
 
 
 
 
60
  ```
 
43
  trust_remote_code=True)
44
  tokenizer = AutoTokenizer.from_pretrained("ManishThota/Sparrow", trust_remote_code=True)
45
 
46
+ #function to generate the answer
47
+ def predict(question, image_path):
48
+ #Set inputs
49
+ text = f"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\n{question}? ASSISTANT:"
50
+ image = Image.open(image_path)
51
+
52
+ input_ids = tokenizer(text, return_tensors='pt').input_ids
53
+ image_tensor = model.image_preprocess(image)
54
+
55
+ #Generate the answer
56
+ output_ids = model.generate(
57
+ input_ids,
58
+ max_new_tokens=25,
59
+ images=image_tensor,
60
+ use_cache=True)[0]
61
+
62
+ return tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
63
+
64
  ```