YigitSekerci commited on
Commit
63d9bd0
·
1 Parent(s): eff95ca

create basic ui with streaming

Browse files
Files changed (1) hide show
  1. src/ui.py +73 -0
src/ui.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import gradio as gr
3
+ from .agent import AudioAgent
4
+
5
+ # Global agent instance
6
+ agent = AudioAgent()
7
+
8
+ async def chat_with_agent(message):
9
+ """
10
+ Stream chat with the audio agent
11
+ """
12
+ if not message.strip():
13
+ yield "Please enter a message."
14
+ return
15
+
16
+ try:
17
+ # Initialize agent if not already done
18
+ if not agent.is_initialized:
19
+ await agent.initialize()
20
+
21
+ # Stream the response
22
+ full_response = ""
23
+ async for chunk in agent.stream_chat(message):
24
+ full_response += chunk
25
+ yield full_response
26
+
27
+ except Exception as e:
28
+ yield f"Error: {str(e)}"
29
+
30
+ def create_interface():
31
+ """
32
+ Create and return the Gradio interface
33
+ """
34
+ with gr.Blocks(title="Audio Agent Chatbot") as demo:
35
+ gr.Markdown("# 🎵 Audio Agent Chatbot")
36
+ gr.Markdown("Chat with your audio agent! Ask about available tools or audio processing.")
37
+
38
+ with gr.Row():
39
+ with gr.Column():
40
+ user_input = gr.Textbox(
41
+ label="Your Message",
42
+ placeholder="Ask about audio tools or processing...",
43
+ lines=3
44
+ )
45
+ submit_btn = gr.Button("Send", variant="primary")
46
+
47
+ with gr.Column():
48
+ output = gr.Textbox(
49
+ label="Agent Response",
50
+ lines=10,
51
+ max_lines=20,
52
+ interactive=False
53
+ )
54
+
55
+ # Handle submit
56
+ submit_btn.click(
57
+ fn=chat_with_agent,
58
+ inputs=[user_input],
59
+ outputs=[output]
60
+ )
61
+
62
+ # Also handle enter key
63
+ user_input.submit(
64
+ fn=chat_with_agent,
65
+ inputs=[user_input],
66
+ outputs=[output]
67
+ )
68
+
69
+ return demo
70
+
71
+ if __name__ == "__main__":
72
+ demo = create_interface()
73
+ demo.launch(share=False, server_name="0.0.0.0", server_port=7861)