File size: 2,911 Bytes
6fe80c5
163e91e
 
8d5e3ad
5a3afcf
6fe80c5
 
 
8d5e3ad
5a3afcf
8d5e3ad
8df9d74
5a3afcf
6fe80c5
 
 
163e91e
 
b3a9df5
163e91e
 
 
b3a9df5
8df9d74
 
 
 
 
 
 
 
 
 
 
 
 
 
163e91e
b3a9df5
8df9d74
b3a9df5
 
8df9d74
 
 
 
 
 
 
b3a9df5
8df9d74
 
b3a9df5
8df9d74
 
 
 
 
 
 
 
b3a9df5
163e91e
 
 
 
 
 
 
 
b3a9df5
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import gradio as gr
from model.controller import Controller
import zipfile

os.chdir("/home/user/app")

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"')
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"')

with zipfile.ZipFile("chromadb_collection.zip", 'r') as zip_ref:
    zip_ref.extractall()

os.system('mv content/chromadb_collections chromadb_collections')
os.system('rm -r content')

bot = Controller()

# Define chatbot function
def chatbot_interface(user_input, chat_id=2311):
    return bot.handle_message(chat_id, user_input)

# Custom CSS to load and apply Vazir font
custom_css = """
@font-face {
    font-family: 'Vazir';
    src: url('https://cdn.jsdelivr.net/gh/rastikerdar/vazir-font/vf/Vazir.woff2') format('woff2'),
         url('https://cdn.jsdelivr.net/gh/rastikerdar/vazir-font/vf/Vazir.woff') format('woff');
}
.gradio-container {
    background-color: #f9f9f9;
}
.chatbox, .inputbox {
    font-family: 'Vazir', sans-serif;
    font-size: 16px;
}
"""

# Define Gradio interface with legal emojis and enhanced appearance
with gr.Blocks(css=custom_css) as interface:
    
    # Introduction and Instructions with law-related emojis
    gr.Markdown("""
    <div style="text-align: center; font-family: 'Vazir';">
    <h1 style="color: #4a90e2;">βš–οΈ RAG Law Chatbot βš–οΈ</h1>
    <p style="font-size: 18px; color: #333;">Welcome to the legal chatbot! πŸ‘¨β€βš–οΈπŸ‘©β€βš–οΈ<br>Ask any legal question, and our assistant will help you! πŸ“œπŸ›οΈ</p>
    </div>
    """)
    
    with gr.Column():  # Replacing Box() with Column()
        chatbot = gr.Chatbot(label="πŸ§‘β€βš–οΈ Legal Chatbot Assistant πŸ§‘β€βš–οΈ", elem_classes=["chatbox"]).style(height=400)
    
    # Customize the input box and button area with emojis
    with gr.Row():
        user_input = gr.Textbox(show_label=False, placeholder="Enter your law question here... βš–οΈ", elem_classes=["inputbox"]).style(
            container=True, border_color="#4a90e2", rounded=True, background_color="#f1f3f4", font_size="16px"
        )
        send_button = gr.Button("πŸ“€ Send", variant="primary").style(
            padding="10px 20px", background_color="#4a90e2", color="white", rounded=True
        )
    
    # Chat update function
    def chat_update(user_message, history):
        history = history or []
        bot_reply = chatbot_interface(user_message)
        history.append((user_message, bot_reply))
        return history, ""

    send_button.click(chat_update, [user_input, chatbot], [chatbot, user_input])

# Launch the Gradio interface with more appealing design and emojis
interface.launch()