import gradio as gr from Rag_conversation import rag_chain # Import the RAG pipeline from your script from langchain_core.messages import HumanMessage, SystemMessage # Function to process user messages def chatbot(user_message, history): """ :param user_message: The latest user message :param history: A list of (user, ai) tuples from Gradio chat :return: (bot_reply, updated_history) """ chat_history = [] for h in history: chat_history.append(HumanMessage(content=h[0])) # User message chat_history.append(SystemMessage(content=h[1])) # AI response chat_history.append(HumanMessage(content=user_message)) # Add new message # Get response from RAG-based chatbot result = rag_chain.invoke({"input": user_message, "chat_history": chat_history}) bot_reply = result["answer"] return bot_reply # Create Gradio UI demo = gr.ChatInterface( chatbot, title="Binghamton RAG Chatbot", description="Ask questions about Binghamton University.", ) if __name__ == "__main__": demo.launch()