Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -53,11 +53,22 @@ def infer_fin_pali(image, question):
|
|
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, quantization_config=bnb_config,token=access_token).to(device)
|
57 |
-
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True, token=access_token)
|
58 |
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
|
|
61 |
|
62 |
predictions = model.generate(**inputs, max_new_tokens=512)
|
63 |
decoded_output = processor.decode(predictions[0], skip_special_tokens=True)[len(question):].lstrip("\n")
|
|
|
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, quantization_config=bnb_config,token=access_token).to(device)
|
57 |
+
# processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True, token=access_token)
|
58 |
###
|
59 |
+
|
60 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
|
61 |
+
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True)
|
62 |
+
|
63 |
+
prompt = "<OD>"
|
64 |
+
|
65 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
|
66 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
67 |
+
|
68 |
+
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)
|
69 |
|
70 |
+
######
|
71 |
+
# inputs = processor(images=image, text=question, return_tensors="pt").to(device)
|
72 |
|
73 |
predictions = model.generate(**inputs, max_new_tokens=512)
|
74 |
decoded_output = processor.decode(predictions[0], skip_special_tokens=True)[len(question):].lstrip("\n")
|