Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from datasets import load_dataset
|
|
| 9 |
import pandas as pd
|
| 10 |
import requests
|
| 11 |
from io import BytesIO
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
# download model and dataset
|
|
@@ -26,13 +27,15 @@ def read_image_from_url(url):
|
|
| 26 |
response = requests.get(url)
|
| 27 |
img = Image.open(BytesIO(response.content)).convert("RGB")
|
| 28 |
return img
|
| 29 |
-
|
|
|
|
| 30 |
def extract_features_siglip(image):
|
| 31 |
with torch.no_grad():
|
| 32 |
inputs = processor(images=image, return_tensors="pt").to(device)
|
| 33 |
image_features = model.get_image_features(**inputs)
|
| 34 |
return image_features
|
| 35 |
|
|
|
|
| 36 |
def infer(input_image):
|
| 37 |
input_features = extract_features_siglip(input_image["composite"].convert("RGB"))
|
| 38 |
input_features = input_features.detach().cpu().numpy()
|
|
|
|
| 9 |
import pandas as pd
|
| 10 |
import requests
|
| 11 |
from io import BytesIO
|
| 12 |
+
import spaces
|
| 13 |
|
| 14 |
|
| 15 |
# download model and dataset
|
|
|
|
| 27 |
response = requests.get(url)
|
| 28 |
img = Image.open(BytesIO(response.content)).convert("RGB")
|
| 29 |
return img
|
| 30 |
+
|
| 31 |
+
@spaces.GPU
|
| 32 |
def extract_features_siglip(image):
|
| 33 |
with torch.no_grad():
|
| 34 |
inputs = processor(images=image, return_tensors="pt").to(device)
|
| 35 |
image_features = model.get_image_features(**inputs)
|
| 36 |
return image_features
|
| 37 |
|
| 38 |
+
|
| 39 |
def infer(input_image):
|
| 40 |
input_features = extract_features_siglip(input_image["composite"].convert("RGB"))
|
| 41 |
input_features = input_features.detach().cpu().numpy()
|