Spaces:
Sleeping
Sleeping
Fix HF ZeroGPU support: Add spaces decorator
Browse files- requirements.txt +1 -0
- src/app.py +11 -0
requirements.txt
CHANGED
|
@@ -11,3 +11,4 @@ tensorflow-text; sys_platform != 'win32'
|
|
| 11 |
tensorflow
|
| 12 |
pydicom
|
| 13 |
gradio
|
|
|
|
|
|
| 11 |
tensorflow
|
| 12 |
pydicom
|
| 13 |
gradio
|
| 14 |
+
spaces
|
src/app.py
CHANGED
|
@@ -46,6 +46,17 @@ def load_models():
|
|
| 46 |
logger.error(f"Failed to load models: {e}")
|
| 47 |
raise e
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def predict(image):
|
| 50 |
if image is None:
|
| 51 |
return "No image uploaded.", 0.0, "Please upload an image."
|
|
|
|
| 46 |
logger.error(f"Failed to load models: {e}")
|
| 47 |
raise e
|
| 48 |
|
| 49 |
+
# ZeroGPU compatibility for Hugging Face Spaces
|
| 50 |
+
try:
|
| 51 |
+
import spaces
|
| 52 |
+
except ImportError:
|
| 53 |
+
# Dummy decorator if running locally without spaces installed
|
| 54 |
+
class spaces:
|
| 55 |
+
@staticmethod
|
| 56 |
+
def GPU(func):
|
| 57 |
+
return func
|
| 58 |
+
|
| 59 |
+
@spaces.GPU
|
| 60 |
def predict(image):
|
| 61 |
if image is None:
|
| 62 |
return "No image uploaded.", 0.0, "Please upload an image."
|