KrSharangrav
change in the interaction
979706a
raw
history blame
1.12 kB
import streamlit as st
from db import insert_data_if_empty, get_mongo_client
from chatbot import chatbot_response
# Ensure the historical data is inserted into MongoDB if not already present.
insert_data_if_empty()
# (Optional) Connect to MongoDB for further visualization if needed.
collection = get_mongo_client()
st.subheader("💬 Chatbot with Analysis for Specific MongoDB Entries")
st.write("Ask me something (e.g., 'Provide analysis for the data entry 1 in the dataset'): ")
user_prompt = st.text_area("Your Query:")
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 valid query for analysis.")