Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,7 @@ import time
|
|
| 24 |
import timeout_decorator
|
| 25 |
import socket
|
| 26 |
import ipaddress
|
|
|
|
| 27 |
from huggingface_hub import spaces
|
| 28 |
|
| 29 |
# Setup logging
|
|
@@ -59,6 +60,19 @@ MAX_IMAGE_RES = (1920, 1080)
|
|
| 59 |
MAX_VIDEO_MB = 50
|
| 60 |
MAX_VIDEO_DURATION = 30 # seconds
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# Utility Functions
|
| 63 |
def format_error(message):
|
| 64 |
"""Formats error messages for consistent user feedback."""
|
|
@@ -461,8 +475,4 @@ with gr.Blocks() as demo:
|
|
| 461 |
)
|
| 462 |
|
| 463 |
# Launch the Gradio App
|
| 464 |
-
|
| 465 |
-
def launch_app():
|
| 466 |
-
demo.launch()
|
| 467 |
-
|
| 468 |
-
launch_app()
|
|
|
|
| 24 |
import timeout_decorator
|
| 25 |
import socket
|
| 26 |
import ipaddress
|
| 27 |
+
from huggingface_hub import hf_hub_download
|
| 28 |
from huggingface_hub import spaces
|
| 29 |
|
| 30 |
# Setup logging
|
|
|
|
| 60 |
MAX_VIDEO_MB = 50
|
| 61 |
MAX_VIDEO_DURATION = 30 # seconds
|
| 62 |
|
| 63 |
+
@spaces.GPU
|
| 64 |
+
def preload_models():
|
| 65 |
+
"""
|
| 66 |
+
This function is needed to activate ZeroGPU. It must be decorated with @spaces.GPU.
|
| 67 |
+
It can be used to warm up models or load them into memory.
|
| 68 |
+
"""
|
| 69 |
+
from registry import get_model
|
| 70 |
+
print("Warming up models for ZeroGPU...")
|
| 71 |
+
get_model("detection", "yolov5n-seg", device="cpu")
|
| 72 |
+
get_model("segmentation", "deeplabv3_resnet50", device="cpu")
|
| 73 |
+
get_model("depth", "midas_v21_small_256", device="cpu")
|
| 74 |
+
|
| 75 |
+
|
| 76 |
# Utility Functions
|
| 77 |
def format_error(message):
|
| 78 |
"""Formats error messages for consistent user feedback."""
|
|
|
|
| 475 |
)
|
| 476 |
|
| 477 |
# Launch the Gradio App
|
| 478 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|