BinghamtonAI / app.py
ashfaq93's picture
Update app.py
470ff4b verified
raw
history blame
1.04 kB
import os
from dotenv import load_dotenv
# Load .env from the root directory
load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), ".env"))
from Rag_conversation import rag_chain # Now import the chatbot pipeline
import gradio as gr
from langchain_core.messages import HumanMessage, SystemMessage
# Function to process user messages
def chatbot(user_message, 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()