Spaces:
Runtime error
Runtime error
Fix: move HF_HOME writability check before gradio import
Browse files- src/service/app.py +18 -0
- src/service/pipeline.py +5 -15
src/service/app.py
CHANGED
|
@@ -14,6 +14,24 @@ un utilisateur Gradio et un client WebSocket externe ne peuvent donc jamais
|
|
| 14 |
lancer deux inferences GPU en concurrence.
|
| 15 |
"""
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
import asyncio
|
| 18 |
import base64
|
| 19 |
import io
|
|
|
|
| 14 |
lancer deux inferences GPU en concurrence.
|
| 15 |
"""
|
| 16 |
|
| 17 |
+
import os
|
| 18 |
+
|
| 19 |
+
# DOIT s'executer avant TOUT import touchant huggingface_hub (gradio inclus -
|
| 20 |
+
# gradio importe huggingface_hub en interne). huggingface_hub fige HF_HOME
|
| 21 |
+
# comme constante de module des son propre import ; le corriger plus tard
|
| 22 |
+
# (ex. dans pipeline.py, importe apres gradio) ne change plus rien, la
|
| 23 |
+
# constante est deja calculee avec l'ancienne valeur. Cf. PermissionError
|
| 24 |
+
# rencontree au premier deploiement Spaces : /home/user/.cache/huggingface
|
| 25 |
+
# est ecrit pendant le BUILD (preload_from_hub) mais pas inscriptible par
|
| 26 |
+
# l'utilisateur runtime - Florence-2 (trust_remote_code) a besoin d'ecrire
|
| 27 |
+
# dans <HF_HOME>/modules/.
|
| 28 |
+
_hf_home = os.environ.get("HF_HOME", os.path.expanduser("~/.cache/huggingface"))
|
| 29 |
+
try:
|
| 30 |
+
os.makedirs(os.path.join(_hf_home, "modules"), exist_ok=True)
|
| 31 |
+
except PermissionError:
|
| 32 |
+
os.environ["HF_HOME"] = "/tmp/hf_home"
|
| 33 |
+
print(f"[app] HF_HOME ({_hf_home}) non inscriptible au runtime -> repli sur /tmp/hf_home")
|
| 34 |
+
|
| 35 |
import asyncio
|
| 36 |
import base64
|
| 37 |
import io
|
src/service/pipeline.py
CHANGED
|
@@ -14,25 +14,15 @@ utilisable en dev et en production.
|
|
| 14 |
"""
|
| 15 |
|
| 16 |
import io
|
| 17 |
-
import os
|
| 18 |
import time
|
| 19 |
from dataclasses import dataclass
|
| 20 |
from typing import Callable, Optional
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
#
|
| 24 |
-
#
|
| 25 |
-
#
|
| 26 |
-
#
|
| 27 |
-
# PermissionError. On teste l'ecriture et on bascule sur /tmp uniquement si
|
| 28 |
-
# necessaire (le pod de dev, deja inscriptible, n'est pas affecte).
|
| 29 |
-
_hf_home = os.environ.get("HF_HOME", os.path.expanduser("~/.cache/huggingface"))
|
| 30 |
-
try:
|
| 31 |
-
os.makedirs(os.path.join(_hf_home, "modules"), exist_ok=True)
|
| 32 |
-
except PermissionError:
|
| 33 |
-
os.environ["HF_HOME"] = "/tmp/hf_home"
|
| 34 |
-
print(f"[pipeline] HF_HOME ({_hf_home}) non inscriptible au runtime -> repli sur /tmp/hf_home")
|
| 35 |
-
|
| 36 |
import numpy as np
|
| 37 |
import torch
|
| 38 |
from PIL import Image, ImageFilter
|
|
|
|
| 14 |
"""
|
| 15 |
|
| 16 |
import io
|
|
|
|
| 17 |
import time
|
| 18 |
from dataclasses import dataclass
|
| 19 |
from typing import Callable, Optional
|
| 20 |
|
| 21 |
+
# Note : le fix HF_HOME (permissions du cache trust_remote_code sous HF
|
| 22 |
+
# Spaces) vit dans app.py, EXECUTE AVANT le premier import touchant
|
| 23 |
+
# huggingface_hub (gradio inclus). Le mettre ici serait trop tard : gradio
|
| 24 |
+
# est importe en premier dans app.py et fige HF_HOME comme constante de
|
| 25 |
+
# module des son propre import.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
import numpy as np
|
| 27 |
import torch
|
| 28 |
from PIL import Image, ImageFilter
|