Skip to content

Commit

Permalink
Refactor docker dependencies to gradio
Browse files Browse the repository at this point in the history
Cleanup logging
Refactor to resolve warnings
Resolve missing directory exception in audio input handling
  • Loading branch information
NeonDaniel committed Nov 7, 2023
1 parent 94dcd39 commit 39e8fa8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ADD . /neon_iris
WORKDIR /neon_iris

RUN pip install wheel && \
pip install .[docker]
pip install .[gradio]

COPY docker_overlay/ /

Expand Down
1 change: 1 addition & 0 deletions neon_iris/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def _send_serialized_message(self, serialized: dict):
self._connection.connection,
queue="neon_chat_api_request",
request_data=serialized)
LOG.debug(f"emitted {serialized.get('msg_type')}")
except Exception as e:
LOG.exception(e)
self.shutdown()
Expand Down
19 changes: 12 additions & 7 deletions neon_iris/web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from os.path import isfile, join

from os import makedirs
from os.path import isfile, join, isdir
from time import time
from typing import List, Optional

Expand All @@ -49,6 +51,9 @@ def __init__(self, lang: str = None):
self._await_response = Event()
self._response = None
self._current_tts = None
self._audio_path = join(xdg_data_home(), "iris", "stt")
if not isdir(self._audio_path):
makedirs(self._audio_path)
self.lang = lang or self.config.get('default_lang') or \
self.config.get('languages', ['en-us'])[0]
self.chat_ui = gradio.Blocks()
Expand Down Expand Up @@ -80,11 +85,12 @@ def send_audio(self, audio_file: str, lang: str = "en-us",
username: Optional[str] = None,
user_profiles: Optional[list] = None):
"""
@param audio_file: path to audio file to send to speech module
@param audio_file: path to wav audio file to send to speech module
@param lang: language code associated with request
@param username: username associated with request
@param user_profiles: user profiles expecting a response
"""
# TODO: Audio conversion is really slow here. check ovos-stt-http-server
audio_file = self.convert_audio(audio_file)
self._send_audio(audio_file, lang, username, user_profiles)

Expand All @@ -107,7 +113,7 @@ def convert_audio(self, audio_file: str, target_sr=16000, target_channels=1,
# Ensure the audio array is in the correct format (int16 for 2-byte samples)
y_resampled = (y_resampled * (2 ** (8 * 2 - 1))).astype(dtype)

output_path = join(join(xdg_data_home(), "iris", "stt"), f"{time()}.wav")
output_path = join(self._audio_path, f"{time()}.wav")
# Save the audio file with the new sample rate and sample width
sf.write(output_path, y_resampled, target_sr, format='WAV', subtype='PCM_16')
LOG.info(f"Converted audio file to {output_path}")
Expand All @@ -119,8 +125,8 @@ def on_user_input(self, utterance: str, *args, **kwargs) -> str:
@param utterance: String utterance submitted by the user
@returns: String response from Neon (or "ERROR")
"""
LOG.info(args)
LOG.info(kwargs)
# TODO: This should probably queue with a separate iterator thread
LOG.debug(f"args={args}|kwargs={kwargs}")
self._await_response.clear()
self._response = None
if utterance:
Expand Down Expand Up @@ -158,8 +164,7 @@ def run(self):
# Define primary UI
audio_input = gradio.Audio(source="microphone",
type="filepath",
label=speech,
auto_submit=True)
label=speech)
gradio.ChatInterface(self.on_user_input,
chatbot=chatbot,
textbox=textbox,
Expand Down
1 change: 0 additions & 1 deletion requirements/docker.txt

This file was deleted.

3 changes: 3 additions & 0 deletions requirements/gradio.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gradio~=3.28
librosa~=0.9
soundfile~=0.12
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
click~=8.0
click-default-group~=1.2
neon-utils[audio]~=1.0
neon-utils~=1.0
pyyaml>=5.4,<7.0.0
neon-mq-connector~=0.7,>=0.7.1a4
ovos-bus-client~=0.0.3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_requirements(requirements_filename: str):
],
python_requires='>=3.6',
install_requires=get_requirements("requirements.txt"),
extras_require={"docker": get_requirements("docker.txt")},
extras_require={"gradio": get_requirements("gradio.txt")},
entry_points={
'console_scripts': ['iris=neon_iris.cli:neon_iris_cli']
}
Expand Down

0 comments on commit 39e8fa8

Please sign in to comment.