Spaces:
Runtime error
Runtime error
File size: 1,753 Bytes
6fe80c5 163e91e ab004d0 d4e46d5 6fe80c5 4d6ad2d ab004d0 6fe80c5 163e91e 6fe80c5 163e91e d4e46d5 |
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 |
import os
import gradio as gr
from model.controller import Controller
import rarfile
# Install unrar-free and make it available for rarfile to use
os.system('apt-get update && apt-get install -y unrar-free')
# Change working directory to /home/user/app
os.chdir("/home/user/app")
# Download and prepare data files in the correct directory
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.rar "https://drive.usercontent.google.com/download?id=1-3N-QjK6QMogy2mcNEKjTg_9yIrSjh4A&export=download&confirm=t&uuid=ceed27ad-0f81-4c16-b70f-68cebcc55279"')
# Use rarfile to extract the .rar file
rarfile.UNRAR_TOOL = "unrar"
with rarfile.RarFile("chromadb_collection.rar") as rf:
rf.extractall()
os.system('mv content/chromadb_collections chromadb_collections')
os.system('rm -r content')
# Initialize your controller
bot = Controller()
# Define chatbot function
def chatbot_interface(user_input, chat_id=2311):
return bot.handle_message(chat_id, user_input)
# Define Gradio interface
with gr.Blocks() as interface:
gr.Markdown("## RAG Law Chatbot")
chatbot = gr.Chatbot()
user_input = gr.Textbox(show_label=False, placeholder="Enter your law question...")
send_button = gr.Button("Send")
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
interface.launch(share=True)
|