-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.py
53 lines (44 loc) · 1.9 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
# Import other necessary modules and classes here
from google.oauth2 import service_account
from constants import KEY_PATH
from speech_to_text import SpeechToText
from text_to_text import TextToText
from text_to_speech import GoogleCloudTTS, ElevenLabsTTS
from logger import logger
# Initialize your classes and set up any necessary configurations here
credentials = service_account.Credentials.from_service_account_file(KEY_PATH)
s2t = SpeechToText(credentials)
t2t = TextToText(messages=[{"role": "system", "content": "Your initialization message here"}])
# Define a function to handle user input and generate a response
def handle_input(user_input):
try:
# Here you might call s2t.transcribe_audio(audio_file) if you have audio input
# For this example, we're using text input directly
prompt = user_input
text_response = t2t.generate_response(prompt)
return text_response
except Exception as e:
logger.error(str(e))
return "An error occurred."
# Define Streamlit UI elements
st.title("AI Conversational Assistant")
# Create a text area for user input
user_input = st.text_input("Type your message here...")
# Create a button to send the message
if st.button("Send"):
if user_input:
# Display user's message
st.write(f"You: {user_input}")
# Generate and display the assistant’s response
text_response = handle_input(user_input)
st.write(f"Assistant: {text_response}")
# Include options for sound, TTS engine, etc.
want_sound = st.checkbox("Enable sound output")
use_eleven_labs = st.checkbox("Use ElevenLabs for TTS instead of Google Cloud")
if use_eleven_labs:
t2s = ElevenLabsTTS()
else:
t2s = GoogleCloudTTS(credentials)
# If sound is enabled, you can call t2s.synthesize(text_response) here,
# but note that playing audio directly might require additional adjustments or libraries