KrSharangrav
fine tuning changes
f5b718b
raw
history blame
1.6 kB
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.")