Skip to content

Commit

Permalink
cleanup prints, fixed clear conversation from returning
Browse files Browse the repository at this point in the history
  • Loading branch information
bigsk1 committed Jun 29, 2024
1 parent 9e834b6 commit 5f872cb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
15 changes: 2 additions & 13 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ def init_set_provider(set_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)


# Function to display ElevenLabs quota
def display_elevenlabs_quota():
Expand Down Expand Up @@ -194,7 +184,7 @@ async def process_and_play(prompt, audio_file_pth):
if TTS_PROVIDER == 'openai':
output_path = os.path.join(output_dir, 'output.wav')
await openai_text_to_speech(prompt, output_path)
print(f"Generated audio file at: {output_path}")
# print(f"Generated audio file at: {output_path}")
if os.path.exists(output_path):
print("Playing generated audio...")
await send_message_to_clients(json.dumps({"action": "ai_start_speaking"}))
Expand All @@ -205,7 +195,7 @@ async def process_and_play(prompt, audio_file_pth):
elif TTS_PROVIDER == 'elevenlabs':
output_path = os.path.join(output_dir, 'output.mp3')
await elevenlabs_text_to_speech(prompt, output_path)
print(f"Generated audio file at: {output_path}")
# print(f"Generated audio file at: {output_path}")
if os.path.exists(output_path):
print("Playing generated audio...")
await send_message_to_clients(json.dumps({"action": "ai_start_speaking"}))
Expand Down Expand Up @@ -499,7 +489,6 @@ def save_conversation_history(conversation_history):
content = message["content"]
file.write(f"{role}: {content}\n")


def transcribe_with_whisper(audio_file):
segments, info = whisper_model.transcribe(audio_file, beam_size=5)
transcription = ""
Expand Down
2 changes: 1 addition & 1 deletion app/app_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def conversation_loop():

current_character = get_current_character()
await send_message_to_clients(f"{current_character.capitalize()}: {chatbot_response}")
print(f"{current_character.capitalize()}: {chatbot_response}")
# print(f"{current_character.capitalize()}: {chatbot_response}")

def set_env_variable(key: str, value: str):
os.environ[key] = value
Expand Down
7 changes: 2 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
allow_headers=["*"],
)

# @app.on_event("startup")
# async def startup_event():
# asyncio.create_task(user_chatbot_conversation())

@app.get("/")
async def get(request: Request):
Expand Down Expand Up @@ -84,8 +81,8 @@ async def download_history():
@app.post("/clear_history")
async def clear_history():
global conversation_history
conversation_history = []
save_conversation_history(conversation_history)
conversation_history.clear() # Clear the in-memory conversation history
save_conversation_history(conversation_history) # Save the cleared state to the file
return {"status": "cleared"}


Expand Down
5 changes: 3 additions & 2 deletions app/static/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ document.addEventListener("DOMContentLoaded", function() {
console.log("Stop conversation message sent");
});

clearButton.addEventListener('click', function() {
clearButton.addEventListener('click', async function() {
messages.innerHTML = '';
fetch('/clear_history', { method: 'POST' });
await fetch('/clear_history', { method: 'POST' });
console.log("Conversation history cleared.");
});


Expand Down

0 comments on commit 5f872cb

Please sign in to comment.