File size: 1,597 Bytes
0105e3b
af09235
7268351
f5b718b
ea4634d
f5b718b
7268351
ea4634d
f5b718b
7268351
ea4634d
f5b718b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3280b9f
7268351
3280b9f
5a94c8e
7268351
 
 
 
 
5a94c8e
f763dd0
f5b718b
3280b9f
e94ec88
f5b718b
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
import streamlit as st
import pandas as pd
from db import insert_data_if_empty, get_mongo_client
from chatbot import chatbot_response  # Updated chatbot functionality using the fine-tuned model

# 1. Ensure historical data is loaded into MongoDB
insert_data_if_empty()

# 2. Connect to MongoDB collection (for potential historical data display)
collection = get_mongo_client()

# Optional: Display historical data from the dataset (uncomment if needed)
# st.title("📊 Historical Data and Chatbot Analysis")
# st.subheader("Historical Data from MongoDB")
# data = list(collection.find({}, {"_id": 0}).limit(5))
# if data:
#     st.write(pd.DataFrame(data))
# else:
#     st.warning("No data found in MongoDB. Please try refreshing.")
#
# if st.button("Show Complete Data"):
#     all_data = list(collection.find({}, {"_id": 0}))
#     st.write(pd.DataFrame(all_data))

# 3. Chatbot interface
st.subheader("💬 Chatbot with Fine-Tuned Sentiment & Topic Analysis")
user_prompt = st.text_area("Ask me something:")

if st.button("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 Category:** {topic_label} ({topic_confidence:.2f} confidence)")
    else:
        st.warning("Please enter some text for analysis.")