mojtabaa4 commited on
Commit
8df9d74
β€’
1 Parent(s): 6c9fca2

add application files

Browse files
Files changed (1) hide show
  1. app.py +35 -15
app.py CHANGED
@@ -3,35 +3,56 @@ import gradio as gr
3
  from model.controller import Controller
4
  import zipfile
5
 
6
- # Change working directory to /home/user/app
7
  os.chdir("/home/user/app")
8
 
9
- # Download and prepare data files in the correct directory
10
  os.system('wget -O processed_cases.csv "https://drive.usercontent.google.com/download?id=1jMuQtywo0mbj7ZHCCsyE8xurbSyVVCst&export=download&confirm=t&uuid=2f681c98-86f8-4159-9e03-673cdcbc7cb51"')
11
  os.system('wget -O chromadb_collection.zip "https://drive.usercontent.google.com/download?id=1gz5-gxSlySEtPTzL_VPQ9e8jxHFuL0ZJ&export=download&confirm=t&uuid=de946efb-47b3-435d-b432-3bd5c01c73fb"')
12
 
13
- # Use zipfile to extract the .zip file
14
  with zipfile.ZipFile("chromadb_collection.zip", 'r') as zip_ref:
15
- zip_ref.extractall() # Extracts all files into the current directory
16
 
17
  os.system('mv content/chromadb_collections chromadb_collections')
18
  os.system('rm -r content')
19
 
20
- # Initialize your controller
21
  bot = Controller()
22
 
23
- # Define chatbot function
24
  def chatbot_interface(user_input, chat_id=2311):
25
  return bot.handle_message(chat_id, user_input)
26
 
27
- # Define Gradio interface
28
- with gr.Blocks() as interface:
29
- gr.Markdown("## RAG Law Chatbot")
30
-
31
- chatbot = gr.Chatbot()
32
- user_input = gr.Textbox(show_label=False, placeholder="Enter your law question...")
33
- send_button = gr.Button("Send")
 
 
 
 
 
 
 
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  def chat_update(user_message, history):
36
  history = history or []
37
  bot_reply = chatbot_interface(user_message)
@@ -40,5 +61,4 @@ with gr.Blocks() as interface:
40
 
41
  send_button.click(chat_update, [user_input, chatbot], [chatbot, user_input])
42
 
43
- # Launch the Gradio interface
44
- interface.launch()
 
3
  from model.controller import Controller
4
  import zipfile
5
 
 
6
  os.chdir("/home/user/app")
7
 
 
8
  os.system('wget -O processed_cases.csv "https://drive.usercontent.google.com/download?id=1jMuQtywo0mbj7ZHCCsyE8xurbSyVVCst&export=download&confirm=t&uuid=2f681c98-86f8-4159-9e03-673cdcbc7cb51"')
9
  os.system('wget -O chromadb_collection.zip "https://drive.usercontent.google.com/download?id=1gz5-gxSlySEtPTzL_VPQ9e8jxHFuL0ZJ&export=download&confirm=t&uuid=de946efb-47b3-435d-b432-3bd5c01c73fb"')
10
 
 
11
  with zipfile.ZipFile("chromadb_collection.zip", 'r') as zip_ref:
12
+ zip_ref.extractall()
13
 
14
  os.system('mv content/chromadb_collections chromadb_collections')
15
  os.system('rm -r content')
16
 
 
17
  bot = Controller()
18
 
 
19
  def chatbot_interface(user_input, chat_id=2311):
20
  return bot.handle_message(chat_id, user_input)
21
 
22
+ custom_css = """
23
+ @font-face {
24
+ font-family: 'Vazir';
25
+ src: url('https://cdn.jsdelivr.net/gh/rastikerdar/vazir-font/vf/Vazir.woff2') format('woff2'),
26
+ url('https://cdn.jsdelivr.net/gh/rastikerdar/vazir-font/vf/Vazir.woff') format('woff');
27
+ }
28
+ .gradio-container {
29
+ background-color: #f9f9f9;
30
+ }
31
+ .chatbox, .inputbox {
32
+ font-family: 'Vazir', sans-serif;
33
+ font-size: 16px;
34
+ }
35
+ """
36
 
37
+ with gr.Blocks(css=custom_css) as interface:
38
+ gr.Markdown("""
39
+ <div style="text-align: center; font-family: 'Vazir';">
40
+ <h1 style="color: #4a90e2;">βš–οΈ RAG Law Chatbot βš–οΈ</h1>
41
+ <p style="font-size: 18px; color: #333;">Welcome to the legal chatbot! πŸ‘¨β€βš–οΈπŸ‘©β€βš–οΈ<br>Ask any legal question, and our assistant will help you! πŸ“œπŸ›οΈ</p>
42
+ </div>
43
+ """)
44
+
45
+ with gr.Box():
46
+ chatbot = gr.Chatbot(label="πŸ§‘β€βš–οΈ Legal Chatbot Assistant πŸ§‘β€βš–οΈ", elem_classes=["chatbox"]).style(height=400)
47
+
48
+ with gr.Row():
49
+ user_input = gr.Textbox(show_label=False, placeholder="Enter your law question here... βš–οΈ", elem_classes=["inputbox"]).style(
50
+ container=True, border_color="#4a90e2", rounded=True, background_color="#f1f3f4", font_size="16px"
51
+ )
52
+ send_button = gr.Button("πŸ“€ Send", variant="primary").style(
53
+ padding="10px 20px", background_color="#4a90e2", color="white", rounded=True
54
+ )
55
+
56
  def chat_update(user_message, history):
57
  history = history or []
58
  bot_reply = chatbot_interface(user_message)
 
61
 
62
  send_button.click(chat_update, [user_input, chatbot], [chatbot, user_input])
63
 
64
+ interface.launch(share=True)