Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,34 @@
|
|
1 |
from transformers import pipeline, SamModel, SamProcessor
|
2 |
import torch
|
3 |
import numpy as np
|
|
|
4 |
import gradio as gr
|
5 |
from PIL import Image
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# check if cuda is available
|
8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
|
@@ -19,6 +44,7 @@ def apply_mask(image, mask, color):
|
|
19 |
image[:, :, c] = np.where(mask, color[c], image[:, :, c])
|
20 |
return image
|
21 |
|
|
|
22 |
def query(image, texts, threshold):
|
23 |
texts = texts.split(",")
|
24 |
predictions = detector(
|
|
|
1 |
from transformers import pipeline, SamModel, SamProcessor
|
2 |
import torch
|
3 |
import numpy as np
|
4 |
+
import spaces
|
5 |
import gradio as gr
|
6 |
from PIL import Image
|
7 |
|
8 |
+
def find_cuda():
|
9 |
+
# Check if CUDA_HOME or CUDA_PATH environment variables are set
|
10 |
+
cuda_home = os.environ.get('CUDA_HOME') or os.environ.get('CUDA_PATH')
|
11 |
+
|
12 |
+
if cuda_home and os.path.exists(cuda_home):
|
13 |
+
return cuda_home
|
14 |
+
|
15 |
+
# Search for the nvcc executable in the system's PATH
|
16 |
+
nvcc_path = shutil.which('nvcc')
|
17 |
+
|
18 |
+
if nvcc_path:
|
19 |
+
# Remove the 'bin/nvcc' part to get the CUDA installation path
|
20 |
+
cuda_path = os.path.dirname(os.path.dirname(nvcc_path))
|
21 |
+
return cuda_path
|
22 |
+
|
23 |
+
return None
|
24 |
+
|
25 |
+
cuda_path = find_cuda()
|
26 |
+
|
27 |
+
if cuda_path:
|
28 |
+
print(f"CUDA installation found at: {cuda_path}")
|
29 |
+
else:
|
30 |
+
print("CUDA installation not found")
|
31 |
+
|
32 |
# check if cuda is available
|
33 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
34 |
|
|
|
44 |
image[:, :, c] = np.where(mask, color[c], image[:, :, c])
|
45 |
return image
|
46 |
|
47 |
+
@spaces.GPU
|
48 |
def query(image, texts, threshold):
|
49 |
texts = texts.split(",")
|
50 |
predictions = detector(
|