From 1b4a810731945b2c2c91d4647fc11f1584c28410 Mon Sep 17 00:00:00 2001 From: TKS <32640296+bigsk1@users.noreply.github.com> Date: Mon, 24 Jun 2024 18:58:44 -0700 Subject: [PATCH] dynamically change providers in webui --- README.md | 2 +- app/app.py | 26 ++++++++++++++++++-------- app/app_logic.py | 11 +++++++++-- app/static/js/scripts.js | 2 +- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index dc4c07d..166281f 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ For the CLI the voice id in the .env will be used ### Web View - Visual and Audio input / output -Press start to start talking. Take a break hit stop, when ready again hit start again. Press stop to change characters and voices in dropdown. Saying Exit, Leave or Quit is like pressing stop. To change model or speech providers stop server, update env and start again. +Press start to start talking. Take a break hit stop, when ready again hit start again. Press stop to change characters and voices in dropdown. You can also select the Model Provider and TTS Provider you want in the dropdown menu and it will update and use the selected provider moving forward. Saying Exit, Leave or Quit is like pressing stop. http://localhost:8000/ diff --git a/app/app.py b/app/app.py index e2a001f..8be7629 100644 --- a/app/app.py +++ b/app/app.py @@ -99,15 +99,25 @@ def init_xtts_speed(speed_value): XTTS_SPEED = speed_value print(f"Switched to XTTS speed: {speed_value}") +def init_set_tts(set_tts): + global TTS_PROVIDER + TTS_PROVIDER = set_tts + print(f"Switched to TTS Provider: {set_tts}") + +def init_set_provider(set_provider): + global MODEL_PROVIDER + MODEL_PROVIDER = set_provider + print(f"Switched to Model Provider: {set_provider}") + # Initial model and TTS voice setup -if MODEL_PROVIDER == "openai": - init_openai_model(OPENAI_MODEL) - #init_openai_tts_voice(OPENAI_TTS_VOICE) -elif MODEL_PROVIDER == "ollama": - init_ollama_model(OLLAMA_MODEL) - -if TTS_PROVIDER == "elevenlabs": - init_elevenlabs_tts_voice(ELEVENLABS_TTS_VOICE) +# if MODEL_PROVIDER == "openai": +# init_openai_model(OPENAI_MODEL) +# #init_openai_tts_voice(OPENAI_TTS_VOICE) +# elif MODEL_PROVIDER == "ollama": +# init_ollama_model(OLLAMA_MODEL) + +# if TTS_PROVIDER == "elevenlabs": +# init_elevenlabs_tts_voice(ELEVENLABS_TTS_VOICE) # Function to display ElevenLabs quota diff --git a/app/app_logic.py b/app/app_logic.py index edcc0f4..37ed921 100644 --- a/app/app_logic.py +++ b/app/app_logic.py @@ -17,10 +17,13 @@ init_openai_tts_voice, init_elevenlabs_tts_voice, init_xtts_speed, + init_set_tts, + init_set_provider, ) router = APIRouter() + continue_conversation = False conversation_history = [] clients = [] @@ -52,7 +55,7 @@ def process_text(user_input): conversation_history.append({"role": "assistant", "content": chatbot_response}) sanitized_response = sanitize_response(chatbot_response) if len(sanitized_response) > 400: # Limit response length for audio generation - sanitized_response = sanitized_response[:400] + "..." + sanitized_response = sanitized_response[:500] + "..." prompt2 = sanitized_response process_and_play(prompt2, character_audio_file) return chatbot_response @@ -124,4 +127,8 @@ def set_env_variable(key: str, value: str): if key == "ELEVENLABS_TTS_VOICE": init_elevenlabs_tts_voice(value) # Reinitialize Elevenlabs TTS voice if key == "XTTS_SPEED": - init_xtts_speed(value) # Reinitialize XTTS speed \ No newline at end of file + init_xtts_speed(value) # Reinitialize XTTS speed + if key == "TTS_PROVIDER": + init_set_tts(value) # Reinitialize TTS Providers + if key == "MODEL_PROVIDER": + init_set_provider(value) # Reinitialize Model Providers \ No newline at end of file diff --git a/app/static/js/scripts.js b/app/static/js/scripts.js index ec987ef..b2e6c44 100644 --- a/app/static/js/scripts.js +++ b/app/static/js/scripts.js @@ -1,5 +1,5 @@ document.addEventListener("DOMContentLoaded", function() { - const websocket = new WebSocket("ws://localhost:8000/ws"); + const websocket = new WebSocket("ws://localhost:8000/ws"); // can also use `ws://${window.location.hostname}:8000/ws` websocket.onopen = function(event) { console.log("WebSocket is open now.");