KrSharangrav commited on
Commit
2dc8def
Β·
1 Parent(s): b9a2016

emojis added

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. chatbot.py +7 -6
app.py CHANGED
@@ -9,20 +9,20 @@ insert_data_if_empty()
9
  # Connect to MongoDB (optional: for additional visualizations)
10
  collection = get_mongo_client()
11
 
12
- st.subheader("πŸ’¬ Chatbot with Dataset Analysis")
13
  # Updated hint to include examples for basic questions and entry queries.
14
  user_prompt = st.text_area(
15
  "Ask me something (e.g., 'Provide analysis for data entry 1 in the dataset' or 'What is the dataset summary?'):"
16
  )
17
 
18
- if st.button("Get AI Response"):
19
  ai_response, sentiment_label, sentiment_confidence, topic_label, topic_confidence = chatbot_response(user_prompt)
20
  if ai_response:
21
  st.write("### Response:")
22
  st.write(ai_response)
23
  st.write("### Sentiment Analysis:")
24
- st.write(f"**Sentiment:** {sentiment_label} ({sentiment_confidence:.2f} confidence)")
25
  st.write("### Category Extraction:")
26
- st.write(f"**Detected Category:** {topic_label} ({topic_confidence:.2f} confidence)")
27
  else:
28
  st.warning("⚠️ Please enter a question or text for analysis.")
 
9
  # Connect to MongoDB (optional: for additional visualizations)
10
  collection = get_mongo_client()
11
 
12
+ st.subheader("πŸ’¬ Chatbot with Sentiment Analysis & Category Extraction")
13
  # Updated hint to include examples for basic questions and entry queries.
14
  user_prompt = st.text_area(
15
  "Ask me something (e.g., 'Provide analysis for data entry 1 in the dataset' or 'What is the dataset summary?'):"
16
  )
17
 
18
+ if st.button("Get Response"):
19
  ai_response, sentiment_label, sentiment_confidence, topic_label, topic_confidence = chatbot_response(user_prompt)
20
  if ai_response:
21
  st.write("### Response:")
22
  st.write(ai_response)
23
  st.write("### Sentiment Analysis:")
24
+ st.write(f"**Sentiment Detected:** {sentiment_label} ({sentiment_confidence:.2f} confidence)")
25
  st.write("### Category Extraction:")
26
+ st.write(f"**Category Detected:** {topic_label} ({topic_confidence:.2f} confidence)")
27
  else:
28
  st.warning("⚠️ Please enter a question or text for analysis.")
chatbot.py CHANGED
@@ -29,8 +29,9 @@ except Exception as e:
29
 
30
  # Predefined topic labels for classification
31
  TOPIC_LABELS = [
32
- "Technology", "Politics", "Business", "Sports", "Entertainment",
33
- "Health", "Science", "Education", "Finance", "Travel", "Food"
 
34
  ]
35
 
36
  def analyze_sentiment(text):
@@ -39,9 +40,9 @@ def analyze_sentiment(text):
39
  label = result['label']
40
  score = result['score']
41
  sentiment_mapping = {
42
- "LABEL_0": "Negative",
43
- "LABEL_1": "Neutral",
44
- "LABEL_2": "Positive"
45
  }
46
  return sentiment_mapping.get(label, "Unknown"), score
47
  except Exception as e:
@@ -102,7 +103,7 @@ def chatbot_response(user_prompt):
102
  entry_date = entry.get("date", "Unknown")
103
  # Build a static response message with new lines for each field.
104
  ai_response = (
105
- "Let's break down this tweet-like MongoDB entry:\n\n"
106
  f"**Tweet:** {entry_text}\n\n"
107
  f"**User:** {entry_user}\n\n"
108
  f"**Date:** {entry_date}"
 
29
 
30
  # Predefined topic labels for classification
31
  TOPIC_LABELS = [
32
+ "Technology", "Politics", "Business", "Sports", "Entertainment", "Health", "Science",
33
+ "Education", "Finance", "Travel", "Food", "Environment", "Culture", "History", "Art",
34
+ "Litreature", "Automotive", "Law", "Music", "Movies"
35
  ]
36
 
37
  def analyze_sentiment(text):
 
40
  label = result['label']
41
  score = result['score']
42
  sentiment_mapping = {
43
+ "LABEL_0": "😞 Negative",
44
+ "LABEL_1": "😐 Neutral",
45
+ "LABEL_2": "πŸ˜„ Positive"
46
  }
47
  return sentiment_mapping.get(label, "Unknown"), score
48
  except Exception as e:
 
103
  entry_date = entry.get("date", "Unknown")
104
  # Build a static response message with new lines for each field.
105
  ai_response = (
106
+ "Let's break down this MongoDB entry:\n\n"
107
  f"**Tweet:** {entry_text}\n\n"
108
  f"**User:** {entry_user}\n\n"
109
  f"**Date:** {entry_date}"