Spaces:
Sleeping
Sleeping
Commit
·
334daaa
1
Parent(s):
1beb74a
sigh
Browse files
app.py
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
-
import torch
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
import base64
|
| 7 |
import io
|
| 8 |
from typing import Dict, Any
|
| 9 |
-
from transformers import Sam3Model, Sam3Processor
|
| 10 |
import warnings
|
| 11 |
warnings.filterwarnings("ignore")
|
| 12 |
|
|
@@ -14,9 +12,13 @@ warnings.filterwarnings("ignore")
|
|
| 14 |
def sam3_inference(image, text_prompt, confidence_threshold=0.5):
|
| 15 |
"""
|
| 16 |
Standalone GPU function with model initialization for Spaces Stateless GPU
|
| 17 |
-
All CUDA operations must happen inside this decorated function
|
| 18 |
"""
|
| 19 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Initialize model and processor inside GPU function (required for Stateless GPU)
|
| 21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 22 |
model = Sam3Model.from_pretrained(
|
|
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
import base64
|
| 6 |
import io
|
| 7 |
from typing import Dict, Any
|
|
|
|
| 8 |
import warnings
|
| 9 |
warnings.filterwarnings("ignore")
|
| 10 |
|
|
|
|
| 12 |
def sam3_inference(image, text_prompt, confidence_threshold=0.5):
|
| 13 |
"""
|
| 14 |
Standalone GPU function with model initialization for Spaces Stateless GPU
|
| 15 |
+
All CUDA operations and related imports must happen inside this decorated function
|
| 16 |
"""
|
| 17 |
try:
|
| 18 |
+
# Import torch and transformers inside GPU function to avoid main process CUDA init
|
| 19 |
+
import torch
|
| 20 |
+
from transformers import Sam3Model, Sam3Processor
|
| 21 |
+
|
| 22 |
# Initialize model and processor inside GPU function (required for Stateless GPU)
|
| 23 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 24 |
model = Sam3Model.from_pretrained(
|