Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
from PIL import Image
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
# Load models with priority to YOLOv8
|
| 7 |
# Try to load YOLOv8 model first, fall back to YOLOv11 if not available
|
|
@@ -25,13 +34,14 @@ def predict(image):
|
|
| 25 |
results_img = results[0].plot() # Get image with bounding boxes
|
| 26 |
return Image.fromarray(results_img)
|
| 27 |
|
| 28 |
-
# Get example images from the
|
| 29 |
def get_example_images():
|
| 30 |
examples = []
|
| 31 |
image_folder = "images"
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
| 35 |
return examples
|
| 36 |
|
| 37 |
# Create Gradio interface
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
# CRITICAL: Redirect cache to temporary storage to avoid hitting storage limits
|
| 5 |
+
os.environ['TORCH_HOME'] = '/tmp/torch_cache'
|
| 6 |
+
os.environ['HF_HOME'] = '/tmp/huggingface_cache'
|
| 7 |
+
os.environ['TRANSFORMERS_CACHE'] = '/tmp/transformers_cache'
|
| 8 |
+
os.environ['TMPDIR'] = '/tmp'
|
| 9 |
+
torch.hub.set_dir('/tmp/torch_hub')
|
| 10 |
+
|
| 11 |
import gradio as gr
|
| 12 |
from ultralytics import YOLO
|
| 13 |
from PIL import Image
|
|
|
|
| 14 |
|
| 15 |
# Load models with priority to YOLOv8
|
| 16 |
# Try to load YOLOv8 model first, fall back to YOLOv11 if not available
|
|
|
|
| 34 |
results_img = results[0].plot() # Get image with bounding boxes
|
| 35 |
return Image.fromarray(results_img)
|
| 36 |
|
| 37 |
+
# Get example images from the images folder
|
| 38 |
def get_example_images():
|
| 39 |
examples = []
|
| 40 |
image_folder = "images"
|
| 41 |
+
if os.path.exists(image_folder):
|
| 42 |
+
for filename in os.listdir(image_folder):
|
| 43 |
+
if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
|
| 44 |
+
examples.append(os.path.join(image_folder, filename))
|
| 45 |
return examples
|
| 46 |
|
| 47 |
# Create Gradio interface
|