import os import gradio as gr from model.controller import Controller import zipfile # 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.zip "https://drive.usercontent.google.com/download?id=1gz5-gxSlySEtPTzL_VPQ9e8jxHFuL0ZJ&export=download&confirm=t&uuid=de946efb-47b3-435d-b432-3bd5c01c73fb"') # Use zipfile to extract the .zip file with zipfile.ZipFile("chromadb_collection.zip", 'r') as zip_ref: zip_ref.extractall() # Extracts all files into the current directory 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()