Skip to content

Commit

Permalink
dynamically change providers in webui
Browse files Browse the repository at this point in the history
  • Loading branch information
bigsk1 committed Jun 25, 2024
1 parent cc90bba commit 1b4a810
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
26 changes: 18 additions & 8 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions app/app_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion app/static/js/scripts.js
Original file line number Diff line number Diff line change
@@ -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.");
Expand Down

0 comments on commit 1b4a810

Please sign in to comment.