import streamlit as st import pandas as pd from db import insert_data_if_empty, get_mongo_client from chatbot import chatbot_response # Ensure historical data is inserted into MongoDB if not already present. insert_data_if_empty() # Connect to MongoDB (optional: for additional visualizations) collection = get_mongo_client() st.subheader("💬 Chatbot with Sentiment Analysis & Category Extraction") # Updated hint to include examples for basic questions and entry queries. user_prompt = st.text_area( "Ask me something (e.g., 'Provide analysis for data entry 1 in the dataset' or 'What is the dataset summary?'):" ) if st.button("Get Response"): ai_response, sentiment_label, sentiment_confidence, topic_label, topic_confidence = chatbot_response(user_prompt) if ai_response: st.write("### Response:") st.write(ai_response) st.write("### Sentiment Analysis:") # Convert sentiment confidence to percentage format (e.g., 70% confidence) st.write(f"**Sentiment Detected:** {sentiment_label} ({sentiment_confidence * 100:.0f}% confidence)") st.write("### Category Extraction:") st.write(f"**Category Detected:** {topic_label} ({topic_confidence * 100:.0f}% confidence)") else: st.warning("⚠️ Please enter a question or text for analysis.")