CBSE Class 12 AI Project File | AI-BASED EMOTION DETECTION SYSTEM
- Download Documentation (Project file)
- Download Project Code [Copy code to python file]
- Class 12 Artificial Intelligence Practical File
import pandas as pd
print("🧠 Advanced Emotion Detection System (Without TextBlob)")
print("-----------------------------------------------------------")
print("Press 'q' anytime to quit.\n")
# ----------------------------------------------------------
# Emotion Dataset (Pandas DataFrame)
# ----------------------------------------------------------
data = {
"emotion": [
"Happy / Positive",
"Sad / Unhappy",
"Angry / Frustrated",
"Scared / Anxious",
"Surprised / Amazed",
"Love / Affection",
"Bored",
"Confused",
"Disgusted",
"Confident / Motivated"
],
"keywords": [
"happy|joy|excited|great|good|awesome|wonderful|delight|fantastic|pleased|amazing|cheerful|content|satisfied|glad|bright",
"sad|upset|cry|unhappy|depressed|disappointed|hopeless|miserable|gloomy|heartbroken|sorrow|grief|down|lonely",
"angry|mad|furious|irritated|annoyed|rage|hate|frustrated|offended|aggressive|resent|enraged",
"scared|afraid|fear|nervous|worried|anxious|terrified|panic|insecure|tense|phobia",
"surprised|amazed|shocked|astonished|wow|unexpected|stunned|startled|unbelievable",
"love|like|affection|care|adore|fond|admire|attached|romantic|sweet",
"bored|boring|tired|nothing|lazy|dull|uninterested",
"confused|confusing|unsure|unclear|doubt|lost|puzzled|mixed",
"disgust|gross|nasty|dirty|smelly|yuck|vomit|repulsive",
"confident|strong|motivated|determined|brave|fearless|focused|ready"
]
}
df = pd.DataFrame(data)
# ----------------------------------------------------------
# Sentiment Keyword Dataset (Manual Scoring)
# ----------------------------------------------------------
positive_words = ["happy", "joy", "good", "great", "love", "awesome", "amazing", "fantastic", "bright", "cheerful"]
negative_words = ["sad", "bad", "angry", "cry", "upset", "hate", "fear", "worry", "depressed", "miserable"]
# ----------------------------------------------------------
# LOOP UNTIL USER PRESSES Q
# ----------------------------------------------------------
while True:
text = input("\nEnter your sentence (or press 'q' to quit): ").lower().strip()
if text == "q":
print("\n👋 Thank you for using the Emotion Detection System. Goodbye!")
break
detected_emotion = "Neutral / Calm"
# ---------- Emotion Detection ----------
for index, row in df.iterrows():
keyword_list = row['keywords'].split("|")
if any(word in text for word in keyword_list):
detected_emotion = row['emotion']
break
# ---------- Manual Sentiment Score ----------
sentiment_score = 0
for word in positive_words:
if word in text:
sentiment_score += 1
for word in negative_words:
if word in text:
sentiment_score -= 1
# Assign Sentiment Type
if sentiment_score > 0:
sentiment_label = "Positive"
elif sentiment_score < 0:
sentiment_label = "Negative"
else:
sentiment_label = "Neutral"
# ---------- Emoji Output ----------
emoji = {
"Happy / Positive": "😊",
"Sad / Unhappy": "😔",
"Angry / Frustrated": "😠",
"Scared / Anxious": "😨",
"Surprised / Amazed": "😲",
"Love / Affection": "❤️",
"Bored": "😐",
"Confused": "🤔",
"Disgusted": "🤢",
"Confident / Motivated": "💪",
"Neutral / Calm": "🙂"
}
# ---------- Display Output ----------
print("\n-----------------------------")
print(f"Emotion Detected: {emoji[detected_emotion]} {detected_emotion}")
print(f"Sentiment Score: {sentiment_score}")
print(f"Sentiment Type: {sentiment_label}")
print("-----------------------------")