ManishThota commited on
Commit
cb78e99
1 Parent(s): 9da530e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -3,9 +3,9 @@ from PIL import Image
3
  import torch
4
  from transformers import AutoModelForCausalLM, AutoTokenizer
5
 
6
- # Set default device to CUDA for GPU acceleration
7
- device = 'cuda' if torch.cuda.is_available() else "cpu"
8
- # torch.set_default_device("cuda")
9
 
10
  # Initialize the model and tokenizer
11
  model = AutoModelForCausalLM.from_pretrained("ManishThota/Sparrow", torch_dtype=torch.float16,
@@ -44,7 +44,7 @@ def predict_answer(image, question, max_tokens):
44
  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:"
45
  image = image.convert("RGB")
46
 
47
- input_ids = tokenizer(text, return_tensors='pt').input_ids
48
  image_tensor = model.image_preprocess(image)
49
 
50
  #Generate the answer
 
3
  import torch
4
  from transformers import AutoModelForCausalLM, AutoTokenizer
5
 
6
+ # # Set default device to CUDA for GPU acceleration
7
+ # device = 'cuda' if torch.cuda.is_available() else "cpu"
8
+ torch.set_default_device("cuda")
9
 
10
  # Initialize the model and tokenizer
11
  model = AutoModelForCausalLM.from_pretrained("ManishThota/Sparrow", torch_dtype=torch.float16,
 
44
  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:"
45
  image = image.convert("RGB")
46
 
47
+ input_ids = tokenizer(text, return_tensors='pt').input_ids.to("cuda:0", torch.float16)
48
  image_tensor = model.image_preprocess(image)
49
 
50
  #Generate the answer