selamw commited on
Commit
471e89f
·
verified ·
1 Parent(s): 099c873

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -5,6 +5,9 @@ import spaces
5
  import torch
6
  import os
7
 
 
 
 
8
 
9
  access_token = os.getenv('HF_token')
10
  model_id = "selamw/BirdWatcher2"
@@ -41,11 +44,19 @@ def convert_to_markdown(input_text):
41
 
42
  @spaces.GPU
43
  def infer_fin_pali(image, question):
44
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
45
 
46
- model = PaliGemmaForConditionalGeneration.from_pretrained(model_id, quantization_config=bnb_config, token=access_token)
47
- processor = PaliGemmaProcessor.from_pretrained(model_id, token=access_token)
 
48
 
 
 
 
 
 
 
 
49
  inputs = processor(images=image, text=question, return_tensors="pt").to(device)
50
 
51
  predictions = model.generate(**inputs, max_new_tokens=512)
 
5
  import torch
6
  import os
7
 
8
+ from transformers import AutoProcessor, AutoModelForCausalLM
9
+
10
+
11
 
12
  access_token = os.getenv('HF_token')
13
  model_id = "selamw/BirdWatcher2"
 
44
 
45
  @spaces.GPU
46
  def infer_fin_pali(image, question):
47
+ # device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
48
 
49
+ # model = PaliGemmaForConditionalGeneration.from_pretrained(model_id, quantization_config=bnb_config, token=access_token)
50
+ # processor = PaliGemmaProcessor.from_pretrained(model_id, token=access_token)
51
+
52
 
53
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
54
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
55
+
56
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch_dtype, trust_remote_code=True, token=access_token).to(device)
57
+ processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True, token=access_token)
58
+ ###
59
+
60
  inputs = processor(images=image, text=question, return_tensors="pt").to(device)
61
 
62
  predictions = model.generate(**inputs, max_new_tokens=512)