Update README.md
Browse files
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 |
-
#
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
```
|