Spaces:
Sleeping
Sleeping
Fix fonts and add CPU warning
Browse files- Dockerfile +1 -0
- app.py +4 -0
- utils.py +15 -3
Dockerfile
CHANGED
|
@@ -6,6 +6,7 @@ WORKDIR /app
|
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
curl \
|
|
|
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
COPY requirements.txt .
|
|
|
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
curl \
|
| 9 |
+
fonts-liberation \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
COPY requirements.txt .
|
app.py
CHANGED
|
@@ -361,6 +361,10 @@ if prompt:
|
|
| 361 |
if current_session['image'] is None:
|
| 362 |
st.error("Please upload an image first.")
|
| 363 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
with st.status("Analyzing Scene...", expanded=True) as status:
|
| 365 |
detections, updated_history, raw_text, metrics = utils.get_bounding_boxes(
|
| 366 |
current_session['image'],
|
|
|
|
| 361 |
if current_session['image'] is None:
|
| 362 |
st.error("Please upload an image first.")
|
| 363 |
else:
|
| 364 |
+
# Warning for HF Spaces Free Tier
|
| 365 |
+
if "cpu" in str(st.session_state.get('device', 'cpu')):
|
| 366 |
+
st.info("ℹ️ Running on CPU (Free Tier). Complex scenes may take 30-60s to analyze.")
|
| 367 |
+
|
| 368 |
with st.status("Analyzing Scene...", expanded=True) as status:
|
| 369 |
detections, updated_history, raw_text, metrics = utils.get_bounding_boxes(
|
| 370 |
current_session['image'],
|
utils.py
CHANGED
|
@@ -298,18 +298,30 @@ def draw_boxes(image: Image.Image, detections: list):
|
|
| 298 |
|
| 299 |
font = None
|
| 300 |
try:
|
| 301 |
-
|
| 302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
try:
|
| 304 |
font = ImageFont.truetype(fn, scaled_font_size)
|
|
|
|
| 305 |
break
|
| 306 |
-
except:
|
| 307 |
continue
|
| 308 |
except:
|
| 309 |
pass
|
| 310 |
|
| 311 |
if font is None:
|
| 312 |
try:
|
|
|
|
| 313 |
font = ImageFont.load_default()
|
| 314 |
except:
|
| 315 |
pass
|
|
|
|
| 298 |
|
| 299 |
font = None
|
| 300 |
try:
|
| 301 |
+
# Search paths for fonts (Linux/Windows)
|
| 302 |
+
font_paths = [
|
| 303 |
+
# Windows
|
| 304 |
+
"arial.ttf", "calibri.ttf", "seguiemj.ttf",
|
| 305 |
+
# Linux (Standard)
|
| 306 |
+
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
|
| 307 |
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
| 308 |
+
"LiberationSans-Regular.ttf",
|
| 309 |
+
"DejaVuSans.ttf"
|
| 310 |
+
]
|
| 311 |
+
|
| 312 |
+
for fn in font_paths:
|
| 313 |
try:
|
| 314 |
font = ImageFont.truetype(fn, scaled_font_size)
|
| 315 |
+
print(f"Loaded font: {fn}")
|
| 316 |
break
|
| 317 |
+
except Exception as e:
|
| 318 |
continue
|
| 319 |
except:
|
| 320 |
pass
|
| 321 |
|
| 322 |
if font is None:
|
| 323 |
try:
|
| 324 |
+
print("Fallback to default font (Warning: Text may be tiny)")
|
| 325 |
font = ImageFont.load_default()
|
| 326 |
except:
|
| 327 |
pass
|