

feat: api route to download model
@9ccd70484d6d0840d8a0d6dc417189aafb82260d
--- src/faster_whisper_server/main.py
+++ src/faster_whisper_server/main.py
... | ... | @@ -25,8 +25,10 @@ |
25 | 25 |
from faster_whisper import WhisperModel |
26 | 26 |
from faster_whisper.vad import VadOptions, get_speech_timestamps |
27 | 27 |
import huggingface_hub |
28 |
+from huggingface_hub.hf_api import RepositoryNotFoundError |
|
28 | 29 |
from pydantic import AfterValidator |
29 | 30 |
|
31 |
+from faster_whisper_server import hf_utils |
|
30 | 32 |
from faster_whisper_server.asr import FasterWhisperASR |
31 | 33 |
from faster_whisper_server.audio import AudioStream, audio_samples_from_file |
32 | 34 |
from faster_whisper_server.config import ( |
... | ... | @@ -108,6 +110,17 @@ |
108 | 110 |
return Response(status_code=200, content="OK") |
109 | 111 |
|
110 | 112 |
|
113 |
+@app.post("/api/pull/{model_name:path}", tags=["experimental"], summary="Download a model from Hugging Face.") |
|
114 |
+def pull_model(model_name: str) -> Response: |
|
115 |
+ if hf_utils.does_local_model_exist(model_name): |
|
116 |
+ return Response(status_code=200, content="Model already exists") |
|
117 |
+ try: |
|
118 |
+ huggingface_hub.snapshot_download(model_name, repo_type="model") |
|
119 |
+ except RepositoryNotFoundError as e: |
|
120 |
+ return Response(status_code=404, content=str(e)) |
|
121 |
+ return Response(status_code=201, content="Model downloaded") |
|
122 |
+ |
|
123 |
+ |
|
111 | 124 |
@app.get("/api/ps", tags=["experimental"], summary="Get a list of loaded models.") |
112 | 125 |
def get_running_models() -> dict[str, list[str]]: |
113 | 126 |
return {"models": list(loaded_models.keys())} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?