Spaces:
Paused
Paused
ManishThota
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,13 +3,9 @@ from PIL import Image
|
|
3 |
import torch
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
|
6 |
-
#Setting device to cuda
|
7 |
-
torch.set_default_device("cuda")
|
8 |
|
9 |
# # Ensure GPU usage if available
|
10 |
-
|
11 |
-
|
12 |
-
torch.set_default_dtype()('torch.cuda.FloatTensor')
|
13 |
|
14 |
|
15 |
|
@@ -25,7 +21,7 @@ def predict_answer(image, question, max_tokens=100):
|
|
25 |
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:"
|
26 |
image = image.convert("RGB")
|
27 |
|
28 |
-
input_ids = tokenizer(text, return_tensors='pt').input_ids.to(
|
29 |
image_tensor = model.image_preprocess(image)
|
30 |
|
31 |
#Generate the answer
|
|
|
3 |
import torch
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
|
|
|
|
|
6 |
|
7 |
# # Ensure GPU usage if available
|
8 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
9 |
|
10 |
|
11 |
|
|
|
21 |
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:"
|
22 |
image = image.convert("RGB")
|
23 |
|
24 |
+
input_ids = tokenizer(text, return_tensors='pt').input_ids.to(device)
|
25 |
image_tensor = model.image_preprocess(image)
|
26 |
|
27 |
#Generate the answer
|