Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,9 +11,14 @@ app = FastAPI()
|
|
| 11 |
BOT_USERNAME = "@DiscussionBot"
|
| 12 |
MODEL = "gpt2"
|
| 13 |
|
| 14 |
-
# Définir un répertoire de cache accessible
|
| 15 |
-
CACHE_DIR = os.getenv("HF_HOME", "/
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Vérification du jeton et connexion à Hugging Face
|
| 19 |
try:
|
|
@@ -30,6 +35,7 @@ except Exception as e:
|
|
| 30 |
# Initialisation du pipeline
|
| 31 |
try:
|
| 32 |
pipe = pipeline("text-generation", model=MODEL, token=HF_TOKEN if HF_TOKEN else None, cache_dir=CACHE_DIR)
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
print(f"Failed to initialize pipeline for model {MODEL}: {str(e)}")
|
| 35 |
raise
|
|
|
|
| 11 |
BOT_USERNAME = "@DiscussionBot"
|
| 12 |
MODEL = "gpt2"
|
| 13 |
|
| 14 |
+
# Définir un répertoire de cache accessible pour Hugging Face Spaces
|
| 15 |
+
CACHE_DIR = os.getenv("HF_HOME", "/tmp/cache/huggingface")
|
| 16 |
+
try:
|
| 17 |
+
os.makedirs(CACHE_DIR, exist_ok=True) # Créer le répertoire s'il n'existe pas
|
| 18 |
+
print(f"Cache directory set to {CACHE_DIR}")
|
| 19 |
+
except Exception as e:
|
| 20 |
+
print(f"Warning: Unable to create cache directory {CACHE_DIR}: {str(e)}")
|
| 21 |
+
raise
|
| 22 |
|
| 23 |
# Vérification du jeton et connexion à Hugging Face
|
| 24 |
try:
|
|
|
|
| 35 |
# Initialisation du pipeline
|
| 36 |
try:
|
| 37 |
pipe = pipeline("text-generation", model=MODEL, token=HF_TOKEN if HF_TOKEN else None, cache_dir=CACHE_DIR)
|
| 38 |
+
print(f"Successfully initialized pipeline for model {MODEL}")
|
| 39 |
except Exception as e:
|
| 40 |
print(f"Failed to initialize pipeline for model {MODEL}: {str(e)}")
|
| 41 |
raise
|