mojtabaa4 commited on
Commit
163e91e
1 Parent(s): 6ee47c4

add application files

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. model/controller.py +2 -2
app.py CHANGED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from model.controller import Controller
3
+
4
+ # Initialize your controller
5
+ bot = Controller()
6
+
7
+ # Define chatbot function
8
+ def chatbot_interface(user_input, chat_id=2311):
9
+ return bot.handle_message(chat_id, user_input)
10
+
11
+ # Define Gradio interface
12
+ with gr.Blocks() as interface:
13
+ gr.Markdown("## RAG Law Chatbot")
14
+
15
+ chatbot = gr.Chatbot()
16
+ user_input = gr.Textbox(show_label=False, placeholder="Enter your law question...").style(container=False)
17
+ send_button = gr.Button("Send")
18
+
19
+ def chat_update(user_message, history):
20
+ history = history or []
21
+ bot_reply = chatbot_interface(user_message)
22
+ history.append((user_message, bot_reply))
23
+ return history, ""
24
+
25
+ send_button.click(chat_update, [user_input, chatbot], [chatbot, user_input])
26
+
27
+ # Launch the Gradio interface
28
+ interface.launch()
model/controller.py CHANGED
@@ -1,5 +1,6 @@
1
- %%writefile model/controller.py
2
  from model.chat import *
 
 
3
 
4
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
5
 
@@ -15,4 +16,3 @@ class Controller:
15
  self.chat_dic[chat_id] = Chat(chat_id=chat_id, rag_handler=self.rag_handler)
16
  chat = self.chat_dic[chat_id]
17
  return chat.response(message)
18
- x
 
 
1
  from model.chat import *
2
+ import sys
3
+ import os
4
 
5
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
6
 
 
16
  self.chat_dic[chat_id] = Chat(chat_id=chat_id, rag_handler=self.rag_handler)
17
  chat = self.chat_dic[chat_id]
18
  return chat.response(message)