Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,8 +21,12 @@ def load_model():
|
|
21 |
"google/paligemma2-28b-pt-896", use_auth_token=token
|
22 |
)
|
23 |
model = AutoModelForImageTextToText.from_pretrained(
|
24 |
-
"google/paligemma2-28b-pt-896", use_auth_token=token
|
25 |
)
|
|
|
|
|
|
|
|
|
26 |
|
27 |
return processor, model
|
28 |
|
@@ -33,7 +37,7 @@ def process_image(image):
|
|
33 |
processor, model = load_model()
|
34 |
|
35 |
# Preprocess the image
|
36 |
-
inputs = processor(images=image, return_tensors="pt")
|
37 |
|
38 |
# Generate predictions
|
39 |
with torch.no_grad():
|
|
|
21 |
"google/paligemma2-28b-pt-896", use_auth_token=token
|
22 |
)
|
23 |
model = AutoModelForImageTextToText.from_pretrained(
|
24 |
+
"google/paligemma2-28b-pt-896", use_auth_token=token, torch_dtype=torch.float16
|
25 |
)
|
26 |
+
|
27 |
+
# Move model to GPU if available
|
28 |
+
if torch.cuda.is_available():
|
29 |
+
model = model.to("cuda")
|
30 |
|
31 |
return processor, model
|
32 |
|
|
|
37 |
processor, model = load_model()
|
38 |
|
39 |
# Preprocess the image
|
40 |
+
inputs = processor(images=image, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu", dtype=torch.float16)
|
41 |
|
42 |
# Generate predictions
|
43 |
with torch.no_grad():
|