Skip to content

Commit d06708e

Browse files
committed
Fix pipy build
1 parent 750ac2d commit d06708e

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

llama_assistant/model_handler.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Llava15ChatHandler,
1010
Llava16ChatHandler,
1111
)
12+
from huggingface_hub import hf_hub_download
13+
from tqdm import tqdm
1214

1315
from llama_assistant import config
1416
from llama_assistant.agent import RAGAgent
@@ -86,54 +88,88 @@ def load_agent(
8688
if model.is_online():
8789
if model.model_type == "text" or model.model_type == "text-reasoning":
8890
print("load online model")
89-
loaded_model = Llama.from_pretrained(
91+
# Download with progress bar
92+
model_path = hf_hub_download(
9093
repo_id=model.repo_id,
9194
filename=model.filename,
95+
resume_download=True,
96+
tqdm_class=tqdm,
97+
)
98+
loaded_model = Llama(
99+
model_path=model_path,
92100
n_gpu_layers=-1,
93101
n_ctx=generation_setting["context_len"],
94102
)
95103
elif model.model_type == "image":
96104
if "moondream2" in model.model_id:
105+
print("Downloading vision model projector...")
97106
chat_handler = MoondreamChatHandler.from_pretrained(
98107
repo_id="vikhyatk/moondream2",
99108
filename="*mmproj*",
100109
)
101-
loaded_model = Llama.from_pretrained(
110+
print("Downloading main model...")
111+
model_path = hf_hub_download(
102112
repo_id=model.repo_id,
103113
filename=model.filename,
114+
resume_download=True,
115+
tqdm_class=tqdm,
116+
)
117+
loaded_model = Llama(
118+
model_path=model_path,
104119
chat_handler=chat_handler,
105120
n_ctx=generation_setting["context_len"],
106121
)
107122
elif "MiniCPM" in model.model_id:
123+
print("Downloading vision model projector...")
108124
chat_handler = MiniCPMv26ChatHandler.from_pretrained(
109125
repo_id=model.repo_id,
110126
filename="*mmproj*",
111127
)
112-
loaded_model = Llama.from_pretrained(
128+
print("Downloading main model...")
129+
model_path = hf_hub_download(
113130
repo_id=model.repo_id,
114131
filename=model.filename,
132+
resume_download=True,
133+
tqdm_class=tqdm,
134+
)
135+
loaded_model = Llama(
136+
model_path=model_path,
115137
chat_handler=chat_handler,
116138
n_ctx=generation_setting["context_len"],
117139
)
118140
elif "llava-v1.5" in model.model_id:
141+
print("Downloading vision model projector...")
119142
chat_handler = Llava15ChatHandler.from_pretrained(
120143
repo_id=model.repo_id,
121144
filename="*mmproj*",
122145
)
123-
loaded_model = Llama.from_pretrained(
146+
print("Downloading main model...")
147+
model_path = hf_hub_download(
124148
repo_id=model.repo_id,
125149
filename=model.filename,
150+
resume_download=True,
151+
tqdm_class=tqdm,
152+
)
153+
loaded_model = Llama(
154+
model_path=model_path,
126155
chat_handler=chat_handler,
127156
n_ctx=generation_setting["context_len"],
128157
)
129158
elif "llava-v1.6" in model.model_id:
159+
print("Downloading vision model projector...")
130160
chat_handler = Llava16ChatHandler.from_pretrained(
131161
repo_id=model.repo_id,
132162
filename="*mmproj*",
133163
)
134-
loaded_model = Llama.from_pretrained(
164+
print("Downloading main model...")
165+
model_path = hf_hub_download(
135166
repo_id=model.repo_id,
136167
filename=model.filename,
168+
resume_download=True,
169+
tqdm_class=tqdm,
170+
)
171+
loaded_model = Llama(
172+
model_path=model_path,
137173
chat_handler=chat_handler,
138174
n_ctx=generation_setting["context_len"],
139175
)

llama_assistant/speech_recognition_thread.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pyaudio
88
import wave
99

10-
from whispercpp import Whisper
10+
from whispercpp_kit import WhisperCPP
1111
from llama_assistant.config import llama_assistant_dir
1212

1313

@@ -22,8 +22,9 @@ def __init__(self):
2222
self.stop_listening = False
2323
self.recording = False
2424

25-
# Initialize Whisper model
26-
self.whisper = Whisper("tiny")
25+
# Initialize Whisper model with progress
26+
print("Initializing Whisper model (downloading if needed)...")
27+
self.whisper = WhisperCPP(model_name="tiny")
2728

2829
# Create temporary folder for audio files
2930
self.tmp_audio_folder = llama_assistant_dir / "tmp_audio"
@@ -74,13 +75,10 @@ def run(self):
7475
wf.close()
7576

7677
# Transcribe audio
77-
res = self.whisper.transcribe(str(tmp_filepath))
78-
transcription = self.whisper.extract_text(res)
79-
80-
if isinstance(transcription, list):
81-
# Remove all "[BLANK_AUDIO]" from the transcription
82-
transcription = " ".join(transcription)
83-
transcription = re.sub(r"\[BLANK_AUDIO\]", "", transcription)
78+
transcription = self.whisper.transcribe(str(tmp_filepath))
79+
80+
# Remove all "[BLANK_AUDIO]" from the transcription
81+
transcription = re.sub(r"\[BLANK_AUDIO\]", "", transcription)
8482

8583
if transcription.strip(): # Only emit if there's non-empty transcription
8684
self.finished.emit(transcription)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "llama-assistant"
7-
version = "0.1.43"
7+
version = "0.1.44"
88
authors = [
99
{name = "Viet-Anh Nguyen", email = "vietanh.dev@gmail.com"},
1010
]
@@ -42,7 +42,7 @@ dependencies = [
4242
"mistune==3.0.2",
4343
"paddlepaddle==2.6.2",
4444
"paddleocr==2.9.1",
45-
"whispercpp @ git+https://github.com/stlukey/whispercpp.py"
45+
"whispercpp-kit>=0.1.0",
4646
]
4747
dynamic = []
4848

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ docx2txt==0.8
1616
mistune==3.0.2
1717
paddlepaddle==2.6.2
1818
paddleocr==3.3.2
19-
whispercpp @ git+https://github.com/stlukey/whispercpp.py
19+
whispercpp-kit>=0.1.0

0 commit comments

Comments
 (0)