Skip to content

Commit 1b4a810

Browse files
committed
dynamically change providers in webui
1 parent cc90bba commit 1b4a810

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ For the CLI the voice id in the .env will be used
262262

263263
### Web View - Visual and Audio input / output
264264

265-
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.
265+
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.
266266

267267
http://localhost:8000/
268268

app/app.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,25 @@ def init_xtts_speed(speed_value):
9999
XTTS_SPEED = speed_value
100100
print(f"Switched to XTTS speed: {speed_value}")
101101

102+
def init_set_tts(set_tts):
103+
global TTS_PROVIDER
104+
TTS_PROVIDER = set_tts
105+
print(f"Switched to TTS Provider: {set_tts}")
106+
107+
def init_set_provider(set_provider):
108+
global MODEL_PROVIDER
109+
MODEL_PROVIDER = set_provider
110+
print(f"Switched to Model Provider: {set_provider}")
111+
102112
# Initial model and TTS voice setup
103-
if MODEL_PROVIDER == "openai":
104-
init_openai_model(OPENAI_MODEL)
105-
#init_openai_tts_voice(OPENAI_TTS_VOICE)
106-
elif MODEL_PROVIDER == "ollama":
107-
init_ollama_model(OLLAMA_MODEL)
108-
109-
if TTS_PROVIDER == "elevenlabs":
110-
init_elevenlabs_tts_voice(ELEVENLABS_TTS_VOICE)
113+
# if MODEL_PROVIDER == "openai":
114+
# init_openai_model(OPENAI_MODEL)
115+
# #init_openai_tts_voice(OPENAI_TTS_VOICE)
116+
# elif MODEL_PROVIDER == "ollama":
117+
# init_ollama_model(OLLAMA_MODEL)
118+
119+
# if TTS_PROVIDER == "elevenlabs":
120+
# init_elevenlabs_tts_voice(ELEVENLABS_TTS_VOICE)
111121

112122

113123
# Function to display ElevenLabs quota

app/app_logic.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
init_openai_tts_voice,
1818
init_elevenlabs_tts_voice,
1919
init_xtts_speed,
20+
init_set_tts,
21+
init_set_provider,
2022
)
2123

2224
router = APIRouter()
2325

26+
2427
continue_conversation = False
2528
conversation_history = []
2629
clients = []
@@ -52,7 +55,7 @@ def process_text(user_input):
5255
conversation_history.append({"role": "assistant", "content": chatbot_response})
5356
sanitized_response = sanitize_response(chatbot_response)
5457
if len(sanitized_response) > 400: # Limit response length for audio generation
55-
sanitized_response = sanitized_response[:400] + "..."
58+
sanitized_response = sanitized_response[:500] + "..."
5659
prompt2 = sanitized_response
5760
process_and_play(prompt2, character_audio_file)
5861
return chatbot_response
@@ -124,4 +127,8 @@ def set_env_variable(key: str, value: str):
124127
if key == "ELEVENLABS_TTS_VOICE":
125128
init_elevenlabs_tts_voice(value) # Reinitialize Elevenlabs TTS voice
126129
if key == "XTTS_SPEED":
127-
init_xtts_speed(value) # Reinitialize XTTS speed
130+
init_xtts_speed(value) # Reinitialize XTTS speed
131+
if key == "TTS_PROVIDER":
132+
init_set_tts(value) # Reinitialize TTS Providers
133+
if key == "MODEL_PROVIDER":
134+
init_set_provider(value) # Reinitialize Model Providers

app/static/js/scripts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
document.addEventListener("DOMContentLoaded", function() {
2-
const websocket = new WebSocket("ws://localhost:8000/ws");
2+
const websocket = new WebSocket("ws://localhost:8000/ws"); // can also use `ws://${window.location.hostname}:8000/ws`
33

44
websocket.onopen = function(event) {
55
console.log("WebSocket is open now.");

0 commit comments

Comments
 (0)