mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-10-03 00:55:14 -07:00
Update version handling in backend and improve HuggingFace cache management
- Added __version__ variable in backend/__init__.py to centralize versioning. - Updated main.py to use __version__ for API versioning in the FastAPI app. - Enhanced cache directory handling by utilizing HuggingFace's constants for improved compatibility across platforms.
This commit is contained in:
+3
-3
@@ -34,6 +34,6 @@ replace = "version": "{new_version}"
|
|||||||
search = "version": "{current_version}"
|
search = "version": "{current_version}"
|
||||||
replace = "version": "{new_version}"
|
replace = "version": "{new_version}"
|
||||||
|
|
||||||
[bumpversion:file:backend/main.py]
|
[bumpversion:file:backend/__init__.py]
|
||||||
search = "version": "{current_version}"
|
search = __version__ = "{current_version}"
|
||||||
replace = "version": "{new_version}"
|
replace = __version__ = "{new_version}"
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
# Backend package
|
# Backend package
|
||||||
|
|
||||||
|
__version__ = "0.1.7"
|
||||||
|
|||||||
+22
-11
@@ -19,7 +19,7 @@ import io
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from . import database, models, profiles, history, tts, transcribe, config, export_import, channels, stories
|
from . import database, models, profiles, history, tts, transcribe, config, export_import, channels, stories, __version__
|
||||||
from .database import get_db, Generation as DBGeneration, VoiceProfile as DBVoiceProfile
|
from .database import get_db, Generation as DBGeneration, VoiceProfile as DBVoiceProfile
|
||||||
from .utils.progress import get_progress_manager
|
from .utils.progress import get_progress_manager
|
||||||
from .utils.tasks import get_task_manager
|
from .utils.tasks import get_task_manager
|
||||||
@@ -27,7 +27,7 @@ from .utils.tasks import get_task_manager
|
|||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="voicebox API",
|
title="voicebox API",
|
||||||
description="Production-quality Qwen3-TTS voice cloning API",
|
description="Production-quality Qwen3-TTS voice cloning API",
|
||||||
version="0.1.0",
|
version=__version__,
|
||||||
)
|
)
|
||||||
|
|
||||||
# CORS middleware
|
# CORS middleware
|
||||||
@@ -47,13 +47,13 @@ app.add_middleware(
|
|||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root():
|
||||||
"""Root endpoint."""
|
"""Root endpoint."""
|
||||||
return {"message": "voicebox API", "version": "0.1.7"}
|
return {"message": "voicebox API", "version": __version__}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/health", response_model=models.HealthResponse)
|
@app.get("/health", response_model=models.HealthResponse)
|
||||||
async def health():
|
async def health():
|
||||||
"""Health check endpoint."""
|
"""Health check endpoint."""
|
||||||
from huggingface_hub import hf_hub_download
|
from huggingface_hub import hf_hub_download, constants as hf_constants
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -101,8 +101,8 @@ async def health():
|
|||||||
model_downloaded = True
|
model_downloaded = True
|
||||||
break
|
break
|
||||||
except (ImportError, Exception):
|
except (ImportError, Exception):
|
||||||
# Method 2: Check cache directory
|
# Method 2: Check cache directory (using HuggingFace's OS-specific cache location)
|
||||||
cache_dir = os.path.expanduser("~/.cache/huggingface/hub")
|
cache_dir = hf_constants.HF_HUB_CACHE
|
||||||
repo_cache = Path(cache_dir) / "models--" + default_model_id.replace("/", "--")
|
repo_cache = Path(cache_dir) / "models--" + default_model_id.replace("/", "--")
|
||||||
if repo_cache.exists():
|
if repo_cache.exists():
|
||||||
has_model_files = (
|
has_model_files = (
|
||||||
@@ -994,7 +994,7 @@ async def get_model_progress(model_name: str):
|
|||||||
@app.get("/models/status", response_model=models.ModelStatusListResponse)
|
@app.get("/models/status", response_model=models.ModelStatusListResponse)
|
||||||
async def get_model_status():
|
async def get_model_status():
|
||||||
"""Get status of all available models."""
|
"""Get status of all available models."""
|
||||||
from huggingface_hub import hf_hub_download
|
from huggingface_hub import hf_hub_download, constants as hf_constants
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -1097,10 +1097,10 @@ async def get_model_status():
|
|||||||
pass
|
pass
|
||||||
break
|
break
|
||||||
|
|
||||||
# Method 2: Fallback to checking cache directory directly
|
# Method 2: Fallback to checking cache directory directly (using HuggingFace's OS-specific cache location)
|
||||||
if not downloaded:
|
if not downloaded:
|
||||||
try:
|
try:
|
||||||
cache_dir = os.path.expanduser("~/.cache/huggingface/hub")
|
cache_dir = hf_constants.HF_HUB_CACHE
|
||||||
repo_cache = Path(cache_dir) / "models--" + config["hf_repo_id"].replace("/", "--")
|
repo_cache = Path(cache_dir) / "models--" + config["hf_repo_id"].replace("/", "--")
|
||||||
|
|
||||||
if repo_cache.exists():
|
if repo_cache.exists():
|
||||||
@@ -1232,6 +1232,7 @@ async def delete_model(model_name: str):
|
|||||||
"""Delete a downloaded model from the HuggingFace cache."""
|
"""Delete a downloaded model from the HuggingFace cache."""
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
|
from huggingface_hub import constants as hf_constants
|
||||||
|
|
||||||
# Map model names to HuggingFace repo IDs
|
# Map model names to HuggingFace repo IDs
|
||||||
model_configs = {
|
model_configs = {
|
||||||
@@ -1284,8 +1285,8 @@ async def delete_model(model_name: str):
|
|||||||
if whisper_model.is_loaded() and whisper_model.model_size == config["model_size"]:
|
if whisper_model.is_loaded() and whisper_model.model_size == config["model_size"]:
|
||||||
transcribe.unload_whisper_model()
|
transcribe.unload_whisper_model()
|
||||||
|
|
||||||
# Find and delete the cache directory
|
# Find and delete the cache directory (using HuggingFace's OS-specific cache location)
|
||||||
cache_dir = os.path.expanduser("~/.cache/huggingface/hub")
|
cache_dir = hf_constants.HF_HUB_CACHE
|
||||||
repo_cache_dir = Path(cache_dir) / ("models--" + hf_repo_id.replace("/", "--"))
|
repo_cache_dir = Path(cache_dir) / ("models--" + hf_repo_id.replace("/", "--"))
|
||||||
|
|
||||||
# Check if the cache directory exists
|
# Check if the cache directory exists
|
||||||
@@ -1396,6 +1397,16 @@ async def startup_event():
|
|||||||
print(f"Database initialized at {database._db_path}")
|
print(f"Database initialized at {database._db_path}")
|
||||||
print(f"GPU available: {_get_gpu_status()}")
|
print(f"GPU available: {_get_gpu_status()}")
|
||||||
|
|
||||||
|
# Ensure HuggingFace cache directory exists
|
||||||
|
try:
|
||||||
|
from huggingface_hub import constants as hf_constants
|
||||||
|
cache_dir = Path(hf_constants.HF_HUB_CACHE)
|
||||||
|
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
print(f"HuggingFace cache directory: {cache_dir}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Warning: Could not create HuggingFace cache directory: {e}")
|
||||||
|
print("Model downloads may fail. Please ensure the directory exists and has write permissions.")
|
||||||
|
|
||||||
|
|
||||||
@app.on_event("shutdown")
|
@app.on_event("shutdown")
|
||||||
async def shutdown_event():
|
async def shutdown_event():
|
||||||
|
|||||||
Reference in New Issue
Block a user