KrSharangrav
changes in the topic extraction model
5a94c8e
raw
history blame
1.67 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 chatbot functionality
#### **1. Ensure Data is Inserted Before Display**
insert_data_if_empty()
#### **2. MongoDB Connection**
collection = get_mongo_client()
#### **3. Streamlit App UI**
# st.title("📊 MongoDB Data Viewer with AI Sentiment Chatbot")
# # Show first 5 rows from MongoDB
# st.subheader("First 5 Rows from Database")
# data = list(collection.find({}, {"_id": 0}).limit(5))
# if data:
# st.write(pd.DataFrame(data))
# else:
# st.warning("⚠️ No data found. Try refreshing the app.")
# # Button to show full MongoDB data
# if st.button("Show Complete Data"):
# all_data = list(collection.find({}, {"_id": 0}))
# st.write(pd.DataFrame(all_data))
#### **4. AI Chatbot with Sentiment & Topic Analysis**
st.subheader("🤖 AI Chatbot with Sentiment & Topic Analysis")
# User input for chatbot
user_prompt = st.text_area("Ask AI something or paste text for analysis:")
if st.button("Analyze Sentiment & 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("### Topic Extraction:")
st.write(f"**Detected Topic:** {topic_label} ({topic_confidence:.2f} confidence)")
else:
st.warning("⚠️ Please enter a question or text for analysis.")