Pygmales commited on
Commit
fb7d4a2
·
1 Parent(s): d2162ea

pushed app.py in the root directory

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py CHANGED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from src.rag.agent_chain import ExecutiveAgentChain
3
+ from src.utils.logging import init_logging, get_logger, cached_log_handler
4
+
5
+ init_logging(interactive_mode=False)
6
+ logger = get_logger("chatbot_app")
7
+
8
+ class ChatbotApplication:
9
+ def __init__(self, language: str = 'en') -> None:
10
+ self._language: str = language
11
+ self._agent_chain: ExecutiveAgentChain = ExecutiveAgentChain(language=self._language)
12
+ self._app = gr.Blocks()
13
+
14
+ chatbot: gr.Chatbot = gr.Chatbot(
15
+ value=[
16
+ gr.ChatMessage(
17
+ role='assistant',
18
+ content=self._agent_chain.generate_greeting(),
19
+ )
20
+ ],
21
+ type='messages'
22
+ )
23
+
24
+ with self._app:
25
+ with gr.Row():
26
+ with gr.Row(scale=3):
27
+ gr.ChatInterface(
28
+ chatbot=chatbot,
29
+ fn=self._chat,
30
+ title="Executive Education Adviser",
31
+ type='messages',
32
+ )
33
+ with gr.Row(scale=1):
34
+ log_window = gr.Code(
35
+ label='Console Log',
36
+ lines=30,
37
+ max_lines=30,
38
+ show_line_numbers=False,
39
+ )
40
+
41
+ log_timer = gr.Timer(value=0.5, active=True)
42
+ log_timer.tick(fn=lambda: cached_log_handler.get_logs(), outputs=log_window)
43
+
44
+
45
+ def _chat(self, message: str, history: list[dict]):
46
+ answers = []
47
+ try:
48
+ response = self._agent_chain.query(query=message)
49
+ logger.info("Recieved response from the agent, diplaying answer in the application")
50
+ answers.append(response)
51
+ except Exception as e:
52
+ logger.error(f"Error processing query: {e}")
53
+ answers.append("")
54
+ return answers
55
+
56
+
57
+ def run(self):
58
+ self._app.launch(share=True)