Spaces:
Sleeping
Sleeping
File size: 1,470 Bytes
0105e3b af09235 b03e8ad ea4634d 58c2482 ea4634d 58c2482 af09235 ea4634d bfd707a ea4634d af09235 b03e8ad af09235 b03e8ad 58c2482 b03e8ad bfd707a b03e8ad b6af5ee e94ec88 bfd707a e94ec88 bfd707a b03e8ad bfd707a b03e8ad 38207ff b03e8ad e94ec88 bfd707a |
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 |
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 function
#### **1. Ensure Data is Inserted Before Display**
insert_data_if_empty()
#### **2. MongoDB Connection**
collection = get_mongo_client()
#### **3. Streamlit App to Display Data**
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 Analysis**
st.subheader("🤖 AI Chatbot with Sentiment Analysis")
# User input for chatbot
user_prompt = st.text_area("Ask AI something or paste text for sentiment analysis:")
if st.button("Analyze Sentiment & Get AI Response"):
ai_response, sentiment_label, 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} ({confidence:.2f} confidence)")
else:
st.warning("⚠️ Please enter a question or text for sentiment analysis.")
|