Spaces:
Runtime error
Runtime error
add application files
Browse files
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()
|
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 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
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)
|
|