ManishThota commited on
Commit
a4115fd
1 Parent(s): cb78e99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -31
app.py CHANGED
@@ -3,42 +3,15 @@ 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,
12
- device_map="auto",
13
- trust_remote_code=True).to(device)
 
14
  tokenizer = AutoTokenizer.from_pretrained("ManishThota/Sparrow", trust_remote_code=True)
15
 
16
- # def predict_answer(image, question):
17
- # # Convert PIL image to RGB if not already
18
- # image = image.convert("RGB")
19
-
20
- # # # Format the text input for the model
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
-
23
- # # Tokenize the text input
24
- # encoding = tokenizer(image, question, return_tensors='pt').to(device)
25
-
26
- # out = model.generate(**encoding)
27
- # # Preprocess the image for the model
28
- # generated_text = tokenizer.decode(out[0], skip_special_tokens=True)
29
-
30
- # # # Generate the answer
31
- # # output_ids = model.generate(
32
- # # input_ids,
33
- # # max_new_tokens=100,
34
- # # images=image_tensor,
35
- # # use_cache=True)[0]
36
-
37
- # # # Decode the generated tokens to get the answer
38
- # # answer = tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
39
-
40
- # return generated_text
41
-
42
  def predict_answer(image, question, max_tokens):
43
  #Set inputs
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:"
 
3
  import torch
4
  from transformers import AutoModelForCausalLM, AutoTokenizer
5
 
 
 
6
  torch.set_default_device("cuda")
7
 
8
  # Initialize the model and tokenizer
9
+ model = AutoModelForCausalLM.from_pretrained("ManishThota/Sparrow",
10
+ torch_dtype=torch.float16,
11
+ device_map="auto",
12
+ trust_remote_code=True)
13
  tokenizer = AutoTokenizer.from_pretrained("ManishThota/Sparrow", trust_remote_code=True)
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def predict_answer(image, question, max_tokens):
16
  #Set inputs
17
  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:"