import gradio as gr from langchain_core.messages import HumanMessage, AIMessage from src.agents.main_agent import multi_agent_graph from src.agents.rag_agent import invocation_state from src.configs.config import LOG_DIR import logging import os LOG_FILE = os.path.join(LOG_DIR, "Agents.log") logging.basicConfig( filename=LOG_FILE, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S' ) import pandas as pd invocation_state.invocation_type = 'chatbot' class GradioChatbotApp: def __init__(self): #graph_img = multi_agent_graph.get_graph(xray=True).draw_mermaid_png() #os.makedirs("docs", exist_ok=True) #with open("docs/full_graph.png", "wb") as f: # f.write(graph_img) pass async def process_chat(self, history, user_input): messages = [] for user, bot in history: messages.append(HumanMessage(content=user)) messages.append(AIMessage(content=bot)) messages.append(HumanMessage(content=user_input)) logging.info(f"User query: {user_input}") config = {"configurable": {"thread_id": "1"}} result = await multi_agent_graph.ainvoke({"messages": messages}, config=config) bot_msg = result["messages"][-1].content history.append((user_input, bot_msg)) return history, "" def create_interface(self): # Load CSV and keep only needed columns csv_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../dataset/docs_metadata.csv")) if os.path.exists(csv_path): df_full = pd.read_csv(csv_path) df = df_full[["Catégorie", "Nom du document", "Lien"]] else: df = pd.DataFrame(columns=["Catégorie", "Nom du document", "Lien"]) # Absolute path for logo logo_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "docs", "logo.jpg")) with gr.Blocks(title="HOLOKIA RAG/MCP", theme=gr.themes.Soft()) as demo: with gr.Tab("Chatbot"): # Centered logo gr.HTML(f"""