File size: 1,462 Bytes
970f8d9
e394327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
970f8d9
e394327
 
 
 
 
 
 
 
 
 
 
 
 
 
d5e1184
e394327
 
 
 
970f8d9
 
e394327
 
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
import gradio as gr
from session_manager import NovaSession
from conversation_logic import generate_response
from save_state import save_conversation, load_conversation
from prompts import get_opening_prompt
import audio_utils

nova = NovaSession()
state = {}

def start_conversation(user_audio, session_id=None):
    if session_id and session_id in state:
        history = load_conversation(session_id)
        opening_text = None
    else:
        session_id = nova.start_session()
        opening_text = get_opening_prompt()
        history = [{"role": "system", "content": opening_text}]
        save_conversation(session_id, history)
    
    user_text = nova.audio_to_text(user_audio)
    history.append({"role": "user", "content": user_text})
    
    nova_response = generate_response(history)
    history.append({"role": "assistant", "content": nova_response})
    
    save_conversation(session_id, history)
    
    response_audio = nova.text_to_audio(nova_response)
    
    return response_audio, session_id

iface = gr.Interface(
    fn=start_conversation,
    inputs=[gr.Audio(type="filepath", label="Microphone Input"), gr.Textbox(label="Session ID (leave blank to start new)")],
    outputs=[gr.Audio(type="filepath", label="Nova Response"), gr.Textbox(label="Session ID")],
    live=True,
    title="NovaSpeech Therapy",
    description="Real-time natural conversation speech therapy assistant"
)

if __name__ == "__main__":
    iface.launch()