Update src/florence/model.py
Browse files- src/florence/model.py +5 -4
src/florence/model.py
CHANGED
@@ -3,9 +3,10 @@ import sys
|
|
3 |
import subprocess
|
4 |
from typing import Optional
|
5 |
from PIL import Image
|
6 |
-
import
|
7 |
-
import spaces
|
8 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
|
|
|
|
9 |
|
10 |
# Local imports
|
11 |
from src.logger import logging
|
@@ -23,7 +24,7 @@ subprocess.run(
|
|
23 |
model_id = "microsoft/Florence-2-large-ft"
|
24 |
try:
|
25 |
model = (
|
26 |
-
AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
27 |
.to("cuda")
|
28 |
.eval()
|
29 |
)
|
@@ -60,7 +61,7 @@ def run_example(
|
|
60 |
prompt = task_prompt if text_input is None else task_prompt + text_input
|
61 |
|
62 |
# Process the image and text input
|
63 |
-
inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda")
|
64 |
|
65 |
# Generate the answer using the model
|
66 |
generated_ids = model.generate(
|
|
|
3 |
import subprocess
|
4 |
from typing import Optional
|
5 |
from PIL import Image
|
6 |
+
import torch
|
|
|
7 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
8 |
+
import spaces
|
9 |
+
import gradio as gr
|
10 |
|
11 |
# Local imports
|
12 |
from src.logger import logging
|
|
|
24 |
model_id = "microsoft/Florence-2-large-ft"
|
25 |
try:
|
26 |
model = (
|
27 |
+
AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, trust_remote_code=True)
|
28 |
.to("cuda")
|
29 |
.eval()
|
30 |
)
|
|
|
61 |
prompt = task_prompt if text_input is None else task_prompt + text_input
|
62 |
|
63 |
# Process the image and text input
|
64 |
+
inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda", torch.float16)
|
65 |
|
66 |
# Generate the answer using the model
|
67 |
generated_ids = model.generate(
|