File size: 2,084 Bytes
0105e3b
f89cec9
7268351
be89ae1
ea4634d
f2ddc64
5a308ce
f2ddc64
 
7dccde6
 
 
2ca0ce0
 
 
 
7dccde6
 
84326e0
7268351
ea4634d
84326e0
f89cec9
f37d2cc
f2ddc64
 
 
 
 
 
 
 
 
 
 
 
03c6c0d
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import pandas as pd
from db import insert_data_if_empty, get_mongo_client
from chatbot import chatbot_response

# Sidebar: Display image and title.
st.sidebar.image("https://huggingface.co/spaces/sharangrav24/SentimentAnalysis/resolve/main/sen_analysis.png", width=200)
st.sidebar.markdown("## Group A Submission - Python")

# Sidebar: Add submitted by details.
st.sidebar.markdown("""
**Submitted by-**  
📌Kumar Sharangrav [C] (GMP-21-10)  
📌Amit Sanjeev (GMP-21-01)  
📌Anoop G Zacharia (GMP-21-03)  
📌Anviti Pant (GMP-21-05)
""")

# 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")

# 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"):
    # Check if user has entered text
    if not user_prompt.strip():
         st.warning("⚠️ Please enter a question or text for analysis.")
    else:
         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("⚠️ Unable to generate a response. Please try again.")