KrSharangrav
more changes to all 3 py files
f16063a
raw
history blame
1.02 kB
import streamlit as st
import pandas as pd
from db import insert_data_if_empty, get_mongo_client
from chatbot import chatbot_response # Import the updated chatbot functionality
# Ensure that historical data is in the database
insert_data_if_empty()
# Connect to MongoDB
collection = get_mongo_client()
st.subheader("💬 Chatbot with Sentiment & Topic Analysis")
user_prompt = st.text_area("Ask me something:")
if st.button("Get AI Response"):
ai_response, sentiment_label, sentiment_confidence, topic_label, topic_confidence = chatbot_response(user_prompt)
if ai_response:
st.write("### AI Response:")
st.write(ai_response)
st.write("### Sentiment Analysis:")
st.write(f"**Sentiment:** {sentiment_label} ({sentiment_confidence:.2f} confidence)")
st.write("### Category Extraction:")
st.write(f"**Detected Category:** {topic_label} ({topic_confidence:.2f} confidence)")
else:
st.warning("⚠️ Please enter a question or text for analysis.")