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() # Create a two-column layout: left for the image, right for the chatbot UI. col1, col2 = st.columns([1, 3]) with col1: st.image("https://huggingface.co/spaces/sharangrav24/SentimentAnalysis/resolve/main/sentiment.png", use_column_width=True) with col2: st.subheader("💬 Chatbot with Sentiment Analysis & Category Extraction") # Create an expander to display example questions on separate lines. with st.expander("👋 Hi, allow me to help you with prompts:"): st.write("💡 Provide analysis for data entry 1 in the dataset") st.write("💡 What is the dataset summary?") st.write("💡 or just ask me something of your own, I'll be happy to help 😊") # Text area for user input. user_prompt = st.text_area("Ask me something:") 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.markdown(ai_response) st.write("### Sentiment Analysis:") st.write(f"**Sentiment Detected:** {sentiment_label} ({sentiment_confidence*100:.2f}% confidence)") st.write("### Category Extraction:") st.write(f"**Category Detected:** {topic_label} ({topic_confidence*100:.2f}% confidence)") else: st.warning("⚠️ Please enter a question or text for analysis.")