Skip to content

dhiv06/OSCMiniHack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

86 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ FeeLink: Emotion-Aware P2P Communication System

**F# 4. Run FeeLink (choose one option)

Option 1: Simple & Reliable (Recommended)

python3 start_simple.py

Option 2: Full Featured (with dependency checking)

python3 start_feelink.pyLink** is a peer-to-peer messaging platform that combines real-time emotion detection and personalized wellness recommendations. Built for emergency scenarios where traditional communication infrastructure may be compromised.

✨ Key Features

  • 🧠 Rule-based Emotion Classification - Keyword matching for emotion detection
  • 🌱 Comprehensive Mood Advisor - 700+ wellness recommendations across all emotions
  • πŸ“Š Real-time Analytics Dashboard - Track communication patterns and emotional health
  • πŸ–ΌοΈ Smart Image Compression - OpenCV-powered optimization for faster P2P transfers
  • οΏ½ Message Summarization - Condenses long messages while preserving meaning
  • πŸ”— True P2P Communication - Direct peer-to-peer messaging without servers
  • 🎨 Futuristic UI - Glass morphism design with neon accents and smooth animations

🎯 The Innovation

FeeLink combines P2P messaging with emotion-aware wellness recommendations using simple but effective rule-based classification and TF-IDF summarization.


οΏ½ Quick Setup

Prerequisites

Required Software:

  • Python 3.8+
  • Node.js 14+ (optional, for frontend development)
  • Git

Windows Setup

# 1. Clone the repository
git clone https://github.com/your-username/feelink.git
cd feelink

# 2. Create Python virtual environment
python -m venv venv
.\venv\Scripts\activate

# 3. Install Python dependencies
pip install flask opencv-python scikit-learn flask-cors

# 4. Run FeeLink (choose one option)

# Option 1: Simple & Reliable (Recommended)
python start_simple.py

# Option 2: Full Featured (with dependency checking)
python start_feelink.py

# Option 3: Double-click for Windows users
# Just double-click: start_feelink.bat

Linux/macOS Setup

# 1. Clone the repository
git clone https://github.com/dhiv06/OSCMiniHack.git
cd feelink

# 2. Create Python virtual environment
python3 -m venv venv
source venv/bin/activate

# 3. Install Python dependencies
pip install flask opencv-python scikit-learn flask-cors

# 4. Run FeeLink (choose one option)

# Option 1: Simple & Reliable (Recommended)
python3 start_simple.py

# Option 2: Full Featured (with dependency checking)
python3 start_feelink.py

🌐 Access the Application

  1. Start the server using the commands above
  2. Open your browser and go to: http://localhost:5000
  3. Begin chatting - Your unique P2P ID will be generated automatically
  4. Connect with friends by sharing your ID or entering theirs

πŸš€ Startup Scripts

FeeLink provides multiple startup options for maximum convenience:

⚑ start_simple.py (Recommended)

The most reliable way to start FeeLink - just works every time!

python start_simple.py

Features:

  • βœ… No dependency checking - just starts the backend
  • βœ… Works on all operating systems
  • βœ… Serves frontend at http://localhost:5000
  • βœ… Perfect for development and demos

🎯 start_feelink.py (Full Featured)

Advanced startup with smart dependency detection:

python start_feelink.py

Features:

  • πŸ” Checks Python and Node.js dependencies
  • 🐍 Starts Flask backend (always)
  • βš›οΈ Starts frontend dev server (if Node.js available)
  • πŸ“Š Provides detailed startup status
  • 🌐 Multiple access URLs

πŸ–±οΈ start_feelink.bat (Windows Double-Click)

For Windows users who prefer GUI interaction:

  • Just double-click the start_feelink.bat file
  • Opens a terminal window with startup progress
  • Uses the simple script internally for reliability

πŸ“‹ Platform-Specific Scripts

Traditional PowerShell/Bash scripts for advanced users:

  • Windows: .\scripts\start_all.ps1
  • Linux/Mac: ./scripts/start_all.sh

πŸ—οΈ Architecture Overview

FeeLink uses a hybrid architecture combining a lightweight Flask backend for emotion processing with client-side P2P communication.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Web Browser   β”‚    β”‚   Flask Backend  β”‚    β”‚   Web Browser   β”‚
β”‚                 β”‚    β”‚                  β”‚    β”‚                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  PeerJS   │◄─┼────┼───  AI Engine  β”‚ β”‚    β”‚  β”‚  PeerJS   β”‚  β”‚
β”‚  β”‚ P2P Conn  β”‚  β”‚    β”‚  β”‚             β”‚ β”‚    β”‚  β”‚ P2P Conn  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚    β”‚  β”‚ β€’ Classifierβ”‚ β”‚    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                 β”‚    β”‚  β”‚ β€’ Rewriter  β”‚ β”‚    β”‚                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚    β”‚  β”‚ β€’ Advisor   β”‚ β”‚    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚    UI     │◄─┼────┼─── β€’ Analytics β”‚ β”‚    β”‚  β”‚    UI     β”‚  β”‚
β”‚  β”‚ Futuristicβ”‚  β”‚    β”‚  β”‚ β€’ Compressorβ”‚ β”‚    β”‚  β”‚ Futuristicβ”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       User A              Server (AI Only)            User B

🧠 How It Works: Technical Implementation

1. 🏷️ Emotion Classification System

Technology: Simple keyword dictionary matching

Implementation:

# From classifier.py
def classify_text(text: str) -> Tuple[str, float, List[str]]:
    """Classify text using keyword matching."""
    text_lower = text.lower()
    emotion_scores = {}
    matched_keywords = []
    
    # Check each emotion dictionary
    for emotion, keywords in EMOTION_KEYWORDS.items():
        matches = [kw for kw in keywords if kw in text_lower]
        if matches:
            emotion_scores[emotion] = len(matches) / len(text.split())
            matched_keywords.extend(matches)
    
    # Return highest scoring emotion
    if emotion_scores:
        best_emotion = max(emotion_scores, key=emotion_scores.get)
        confidence = min(emotion_scores[best_emotion] * 2, 1.0)
        return best_emotion, confidence, matched_keywords
    
    return 'normal', 0.5, []

Keyword Database:

EMOTION_KEYWORDS = {
    'happy': {"happy", "joy", "excited", "great", "awesome", "😊", "πŸ˜„", "πŸŽ‰"},
    'sad': {"sad", "depressed", "crying", "tears", "😒", "😭", "πŸ’”"},
    'angry': {"angry", "mad", "furious", "rage", "hate", "😠", "😑", "🀬"},
    'scared': {"scared", "afraid", "terrified", "worried", "😨", "😰", "😱"}
}

2. πŸ“„ Message Summarization

Technology: TF-IDF based extractive summarization

Implementation:

# From summarizer.py
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity

class ExtractiveSummarizer:
    def summarize(self, text: str, max_sentences: int = 2) -> str:
        sentences = self._split_sentences(text)
        if len(sentences) <= max_sentences:
            return text
            
        # Calculate TF-IDF scores
        vectorizer = TfidfVectorizer(stop_words='english')
        tfidf_matrix = vectorizer.fit_transform(sentences)
        
        # Calculate sentence scores
        sentence_scores = np.array(tfidf_matrix.sum(axis=1)).flatten()
        
        # Select top sentences
        top_indices = sentence_scores.argsort()[-max_sentences:][::-1]
        top_indices.sort()  # Maintain original order
        
        return ' '.join([sentences[i] for i in top_indices])

3. 🌱 Mood Advisor System

Implementation: Static dictionary lookup with randomized selection

Database Structure:

# From mood_advisor.py - 700+ tips across all emotions
MOOD_ADVICE = {
    'angry': {
        'immediate': [
            "Take 5 deep breaths - inhale for 4, hold for 4, exhale for 6",
            "Step away from the screen for 2 minutes and look out a window",
            "Drink a full glass of cold water slowly",
            "Do 10 jumping jacks or push-ups to release tension",
            # ... 50+ more immediate tips
        ],
        'daily_habits': [
            "Get 7-8 hours of quality sleep - anger often stems from tiredness",
            "Stay hydrated - drink at least 8 glasses of water daily",
            "Exercise for 20+ minutes to release built-up stress hormones",
            # ... 40+ more daily habits
        ],
        'communication': [
            "Use 'I feel...' statements instead of 'You always...'",
            "Take a 24-hour pause before responding to frustrating messages",
            # ... 30+ more communication tips
        ]
    },
    'sad': { /* 100+ tips */ },
    'scared': { /* 100+ tips */ },
    'happy': { /* 100+ tips */ },
    'normal': { /* 100+ tips */ }
}

def get_mood_advice(emotion: str, confidence: float) -> Dict:
    """Return 2-3 random tips from each category."""
    advice = MOOD_ADVICE.get(emotion, MOOD_ADVICE['normal'])
    return {
        'immediate': random.sample(advice['immediate'], min(3, len(advice['immediate']))),
        'habits': random.sample(advice['daily_habits'], min(2, len(advice['daily_habits']))),
        'communication': random.sample(advice['communication'], min(2, len(advice['communication'])))
    }

Location of 700+ Tips: All wellness recommendations are hardcoded in backend/python-ai/mood_advisor.py lines 8-140, organized by emotion type with immediate actions, daily habits, and communication strategies.

4. πŸ“Š Simple Analytics Tracking

In-Memory Storage:

# From analytics.py
class EmotionAnalytics:
    def __init__(self):
        # Simple list storage: {user_id: [emotion_data, ...]}
        self.emotion_data = defaultdict(list)
    
    def log_emotion(self, user_id: str, emotion: str, confidence: float):
        """Store emotion data with timestamp."""
        self.emotion_data[user_id].append({
            'timestamp': datetime.now(),
            'emotion': emotion,
            'confidence': confidence
        })
    
    def get_emotion_trends(self, user_id: str, days: int = 1):
        """Calculate percentage breakdown of emotions."""
        recent_data = [entry for entry in self.emotion_data[user_id] 
                      if entry['timestamp'] > datetime.now() - timedelta(days=days)]
        
        emotions = [entry['emotion'] for entry in recent_data]
        return {emotion: round((emotions.count(emotion) / len(emotions)) * 100, 1) 
                for emotion in set(emotions)} if emotions else {}

5. πŸ–ΌοΈ Basic Image Compression

Technology: OpenCV with fixed compression settings

Implementation:

# From compressor.py
import cv2

def compress_image(image_bytes, quality=70):
    """Basic JPEG compression using OpenCV."""
    # Convert bytes to numpy array
    nparr = np.frombuffer(image_bytes, np.uint8)
    img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
    
    # Compress with fixed quality setting
    encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), quality]
    result, compressed_img = cv2.imencode('.jpg', img, encode_param)
    
    return compressed_img.tobytes()

Results: Typically 60-80% size reduction with quality=70 setting

6. πŸ”— P2P Communication Architecture

Implementation:

// Frontend P2P connection using PeerJS
class AIChat {
    constructor() {
        this.peer = new Peer(this.generateId());
        this.connection = null;
    }
    
    connect() {
        const friendId = document.getElementById('friendId').value;
        this.connection = this.peer.connect(friendId);
        this.setupConnection(this.connection);
    }
    
    async sendMessage() {
        // Process message through Flask API first
        const analysis = await this.analyzeMessage();
        
        // Send processed data via P2P
        this.connection.send({
            text: analysis.summary,
            emotion: analysis.classification,
            timestamp: new Date().toLocaleTimeString()
        });
    }
}

Message Flow:

  1. User types message β†’ Flask API processes β†’ Classification + Summarization
  2. Processed message sent directly peer-to-peer via WebRTC
  3. Both users see summarized message + emotion tags
  4. Analytics updated in browser memory

7. 🎨 UI Implementation

CSS Technologies:

  • Glass Morphism: backdrop-filter: blur(20px) with translucent backgrounds
  • CSS Grid: Responsive three-column layout
  • CSS Animations: Smooth transitions and hover effects
  • Custom Properties: CSS variables for consistent theming

Design Features:

  • Neon Color Palette: Blue (#00d4ff), Purple (#b19cd9), Pink (#ff006e)
  • Gradient Backgrounds: Multi-layered radial gradients
  • Interactive Elements: Hover animations, loading states, smooth scrolling
  • Mobile-First: Responsive design for all screen sizes

πŸ“ Project Structure

feelink/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ python-ai/           # Main Flask application
β”‚   β”‚   β”œβ”€β”€ app.py           # Flask server with API endpoints
β”‚   β”‚   β”œβ”€β”€ classifier.py    # Emotion classification engine
β”‚   β”‚   β”œβ”€β”€ tone_rewriter.py # Message tone transformation
β”‚   β”‚   β”œβ”€β”€ mood_advisor.py  # Wellness recommendation system
β”‚   β”‚   β”œβ”€β”€ analytics.py     # Real-time emotion analytics
β”‚   β”‚   β”œβ”€β”€ summarizer.py    # Message summarization
β”‚   β”‚   β”œβ”€β”€ compressor.py    # Image compression utilities
β”‚   β”‚   └── static/
β”‚   β”‚       └── index.html   # Frontend UI (futuristic design)
β”‚   β”œβ”€β”€ cpp-mesh/           # Future: C++ mesh networking
β”‚   └── rust-alt/           # Future: Rust alternative backend
β”œβ”€β”€ frontend/               # Development frontend (optional)
β”œβ”€β”€ docs/                   # Documentation and presentations
└── scripts/               # Utility scripts

πŸ”Œ API Endpoints

Core AI Services

Endpoint Method Purpose Input Output
/api/classify POST Emotion classification {text, user_id} {label, score, matched, rewrite_suggestions}

| /api/summarize | POST | Message summarization | {text} | {summary, sentences} | | /api/compress | POST | Image compression | FormData(image) | Compressed image blob | | /api/mood-advice | POST | Wellness recommendations | {emotion, confidence, user_id} | {advice: {immediate, habits, insights}} | | /api/analytics | GET | Emotion analytics | ?user_id=X&days=N | {emotion_breakdown, insights, total_messages} |

Example API Usage

# Classify emotion
response = requests.post('/api/classify', json={
    'text': 'I am so frustrated with this project!',
    'user_id': 'user_123'
})
# Returns: {"label": "angry", "score": 0.85, "matched": ["frustrated"]}

# Get mood advice
response = requests.post('/api/mood-advice', json={
    'emotion': 'angry',
    'confidence': 0.85,
    'user_id': 'user_123'
})
# Returns comprehensive wellness suggestions

πŸ§ͺ Testing and Development

Manual Testing

  1. Emotion Classification Test:

    Happy: "I'm so excited about this!"
    Sad: "I feel really depressed today"
    Angry: "This is so frustrating!"
    Scared: "I'm terrified about the presentation"
    Normal: "Let's meet at 3pm"
    
  2. Tone Transformation Test:

    • Input negative message β†’ Select tone β†’ Verify improved output
  3. P2P Connection Test:

    • Open two browser tabs β†’ Share IDs β†’ Send messages
  4. Analytics Test:

    • Send multiple messages with different emotions
    • Check analytics panel for updated charts

Development Mode

# Enable Flask debug mode (auto-reload on changes)
export FLASK_DEBUG=1  # Linux/Mac
set FLASK_DEBUG=1     # Windows CMD

# Run with verbose logging
python backend/python-ai/app.py --debug

πŸš€ Production Deployment

Docker Deployment (Recommended)

FROM python:3.9-slim

WORKDIR /app
COPY backend/python-ai/ .
RUN pip install flask opencv-python scikit-learn flask-cors

EXPOSE 5000
CMD ["python", "app.py"]

Cloud Deployment Options

  • Heroku: Simple web app deployment
  • AWS EC2: Full server control
  • Google Cloud Run: Serverless container deployment
  • DigitalOcean App Platform: Managed hosting

Environment Variables

# Production configuration
FLASK_ENV=production
FLASK_DEBUG=0
PORT=5000
HOST=0.0.0.0

🀝 Contributing

Development Workflow

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Make changes and test thoroughly
  4. Commit: git commit -m 'Add amazing feature'
  5. Push: git push origin feature/amazing-feature
  6. Create Pull Request

Code Style

  • Python: Follow PEP 8 guidelines
  • JavaScript: Use modern ES6+ syntax
  • CSS: Use consistent naming conventions
  • Comments: Document complex algorithms and AI logic

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ† Project Goals

Built for emergency communication scenarios with simple but effective emotion-aware messaging and wellness recommendations.


πŸ†˜ Troubleshooting

Common Issues

"ModuleNotFoundError: No module named 'cv2'"

pip install opencv-python

"Port 5000 already in use"

# Kill existing process
taskkill /f /im python.exe  # Windows
pkill -f python             # Linux/Mac

"PeerJS connection failed"

  • Check browser console for WebRTC errors
  • Ensure both users are on same network or use STUN servers
  • Try refreshing both browser tabs

"Emotion classification not working"

  • Verify all Python dependencies installed
  • Check Flask logs for import errors
  • Test classifier independently: python -c "from classifier import classify_text; print(classify_text('test'))"

Performance Optimization

  • Memory Usage: Analytics system keeps last 1000 entries per user
  • CPU Usage: Classification is lightweight (simple keyword matching)
  • Network: Images compressed 60-80% for faster P2P transfer
  • Browser: Tested on Chrome, Firefox, Safari, Edge

πŸ“ž Support

For questions, issues, or collaboration opportunities:


FeeLink: Where Emergency Communication Meets Emotional Intelligence πŸš€βœ¨

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •