Use download_model helper for audio pre-load with progress

parent b622fe9e
......@@ -3631,38 +3631,9 @@ def main():
model_path = cached_path
print(f"Using cached model: {model_path}")
else:
# Download and cache
print(f"Downloading audio model: {model_to_use}")
import requests
import hashlib
# Download with progress
cache_dir = get_model_cache_dir()
url_path = model_to_use.split('?')[0]
filename = os.path.basename(url_path)
if not filename.endswith('.gguf'):
filename = "whisper-model.gguf"
url_hash = hashlib.sha256(model_to_use.encode()).hexdigest()
cached_filename = f"{url_hash}_{filename}"
model_path = os.path.join(cache_dir, cached_filename)
response = requests.get(model_to_use, stream=True)
response.raise_for_status()
total_size = int(response.headers.get('content-length', 0))
downloaded = 0
with open(model_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192*1024):
if chunk:
f.write(chunk)
downloaded += len(chunk)
if total_size > 0:
percent = (downloaded / total_size) * 100
print(f"Downloaded: {percent:.1f}%", end='\r')
print(f"\nDownloaded and cached to: {model_path}")
model_path = download_model(model_to_use, cache_dir)
model_to_use = model_path
# Load with llama.cpp (Vulkan)
......@@ -3689,38 +3660,9 @@ def main():
model_path = cached_path
print(f"Using cached model: {model_path}")
else:
# Download and cache
print(f"Downloading audio model: {model_to_use}")
import requests
import hashlib
# Download with progress
cache_dir = get_model_cache_dir()
url_path = model_to_use.split('?')[0]
filename = os.path.basename(url_path)
if not filename.endswith('.bin') and not filename.endswith('.ggml'):
filename = "whisper-model.bin"
url_hash = hashlib.sha256(model_to_use.encode()).hexdigest()
cached_filename = f"{url_hash}_{filename}"
model_path = os.path.join(cache_dir, cached_filename)
response = requests.get(model_to_use, stream=True)
response.raise_for_status()
total_size = int(response.headers.get('content-length', 0))
downloaded = 0
with open(model_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192*1024):
if chunk:
f.write(chunk)
downloaded += len(chunk)
if total_size > 0:
percent = (downloaded / total_size) * 100
print(f"Downloaded: {percent:.1f}%", end='\r')
print(f"\nDownloaded and cached to: {model_path}")
model_path = download_model(model_to_use, cache_dir)
model_to_use = model_path
# Determine compute type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment