@@ -314,12 +364,14 @@ cd notebooks/goemotions-deberta/
## ๐ฏ Future Enhancements
**Model Improvements**
+
- [ ] Expand to 105+ fine-grained emotions
- [ ] Multi-language support (German, Spanish, French)
- [ ] Temporal emotion pattern detection
- [ ] Cross-cultural emotion adaptation
**Production Features**
+
- [ ] A/B testing framework for model comparison
- [ ] Automated model retraining pipeline
- [ ] Real-time model drift detection
@@ -328,6 +380,7 @@ cd notebooks/goemotions-deberta/
## ๐ค Integration Examples
**Backend Integration (Python)**
+
```python
import requests
@@ -340,35 +393,38 @@ def analyze_emotion(text: str) -> dict:
```
**Frontend Integration (JavaScript)**
+
```javascript
async function detectEmotion(text) {
- const response = await fetch('/api/predict', {
- method: 'POST',
- headers: {'Content-Type': 'application/json'},
- body: JSON.stringify({text})
- });
- return await response.json();
+ const response = await fetch("/api/predict", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ text }),
+ });
+ return await response.json();
}
```
-
---
## Support & Resources
### Documentation
+
- [API Documentation](docs/api/API_DOCUMENTATION.md)
- [Integration Guide](docs/guides/INTEGRATION_GUIDE.md)
- [Deployment Guide](docs/DEPLOYMENT_GUIDE.md)
- [Architecture Overview](docs/ARCHITECTURE.md)
### Examples
+
- [Python Integration](examples/python_integration.py)
- [JavaScript Integration](examples/javascript_integration.js)
- [React Component](examples/ReactEmotionDetector.jsx)
- [Vue Component](examples/VueEmotionDetector.vue)
### Testing
+
- [API Test Suite](scripts/testing/)
- [Performance Benchmarks](scripts/testing/benchmarks.py)
- [Integration Tests](scripts/testing/integration_tests.py)
@@ -378,6 +434,7 @@ async function detectEmotion(text) {
## Project Success
### Achievements
+
- **Production Deployment**: Live API with 99.9% uptime
- **Performance Optimization**: 2.3x speedup with ONNX
- **Enterprise Security**: Comprehensive security features
@@ -385,6 +442,7 @@ async function detectEmotion(text) {
- **Documentation**: Complete guides and examples
### Impact
+
- **Model Performance**: 5.20% โ >90% F1 score (+1,630% improvement)
- **System Performance**: 2.3x faster inference
- **Resource Efficiency**: 4x less memory usage
diff --git a/deployment/local/requirements-simple.txt b/deployment/local/requirements-simple.txt
new file mode 100644
index 000000000..c558a4af9
--- /dev/null
+++ b/deployment/local/requirements-simple.txt
@@ -0,0 +1,15 @@
+# Minimal dependencies for SAMO Local Development Server
+# These are the only dependencies needed to run the simple web server
+
+# Web server framework
+Flask==2.3.3
+
+# CORS support for cross-origin requests
+Flask-Cors==4.0.0
+
+# Dependencies automatically installed with Flask:
+# - Werkzeug>=2.3.7
+# - Jinja2>=3.1.2
+# - itsdangerous>=2.1.2
+# - click>=8.1.3
+# - blinker>=1.6.2
diff --git a/deployment/local/simple_server.py b/deployment/local/simple_server.py
new file mode 100644
index 000000000..111267207
--- /dev/null
+++ b/deployment/local/simple_server.py
@@ -0,0 +1,179 @@
+#!/usr/bin/env python3
+"""Simple Web Server for Local Development
+======================================
+
+A lightweight Flask server that serves static website files with CORS enabled
+for testing against deployed Cloud Run APIs.
+
+Usage:
+ python simple_server.py [--port PORT]
+
+Environment Variables:
+ PORT: Server port (default: 8000)
+ ENV: Environment mode ('prod' for production CORS, default: development)
+ ALLOWED_ORIGINS: Comma-separated list of allowed origins for CORS
+"""
+
+import argparse
+import os
+import sys
+from pathlib import Path
+
+try:
+ from flask import Flask, send_from_directory, send_file, jsonify
+ from flask_cors import CORS
+except ImportError:
+ print("โ Missing required dependencies!")
+ print("Please install with: pip install -r requirements-simple.txt")
+ sys.exit(1)
+
+# Get the project root directory (two levels up from this script)
+# Script is at deployment/local/simple_server.py, so we go up 2 levels
+# to get to project root
+PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
+WEBSITE_DIR = PROJECT_ROOT / "website"
+
+app = Flask(__name__)
+
+# Configure CORS based on environment
+is_production = os.getenv("ENV", "").lower() == "prod"
+allowed_origins = os.getenv("ALLOWED_ORIGINS", "")
+
+if is_production:
+ # Production: Use environment variable or default to localhost regex
+ if allowed_origins:
+ origins = [origin.strip() for origin in allowed_origins.split(",")]
+ else:
+ origins = [r"http://localhost:\d+", r"http://127\.0\.0\.1:\d+"]
+
+ CORS(app, origins=origins, supports_credentials=True)
+ print("๐ Production CORS: Restricted origins")
+else:
+ # Development: Allow all origins for easier testing
+ CORS(app, origins="*", supports_credentials=True)
+ print("๐ Development CORS: All origins allowed")
+
+
+@app.route('/', defaults={'filename': 'index.html'})
+@app.route('/
')
+def serve_file(filename):
+ """Serve static files from the website directory."""
+ return send_from_directory(WEBSITE_DIR, filename)
+
+
+@app.route('/health')
+def health_check():
+ """Health check endpoint."""
+ files_available = []
+ if WEBSITE_DIR.exists():
+ files_available = [f.name for f in WEBSITE_DIR.glob("*.html")]
+
+ return jsonify({
+ "status": "healthy",
+ "server": "SAMO Local Development Server",
+ "website_dir": str(WEBSITE_DIR),
+ "cors_mode": "production" if is_production else "development",
+ "files_available": files_available
+ })
+
+
+@app.errorhandler(404)
+def not_found(_error):
+ """Custom 404 handler."""
+ available_files = []
+ if WEBSITE_DIR.exists():
+ available_files = [f.name for f in WEBSITE_DIR.glob("*.html")]
+
+ return jsonify({
+ "error": "Not found",
+ "message": "The requested resource was not found on this server",
+ "available_files": available_files
+ }), 404
+
+
+@app.errorhandler(500)
+def server_error(_error):
+ """Custom 500 handler."""
+ return jsonify({
+ "error": "Internal server error",
+ "message": "An unexpected error occurred"
+ }), 500
+
+
+def validate_environment():
+ """Validate that the environment is set up correctly."""
+ if not WEBSITE_DIR.exists():
+ print(f"โ Website directory not found: {WEBSITE_DIR}")
+ print(f" Make sure you're running this script from: {PROJECT_ROOT}")
+ return False
+
+ index_file = WEBSITE_DIR / "index.html"
+ if not index_file.exists():
+ print(f"โ index.html not found: {index_file}")
+ return False
+
+ print(f"โ
Website directory found: {WEBSITE_DIR}")
+ print(f"โ
Found {len(list(WEBSITE_DIR.glob('*.html')))} HTML files")
+ return True
+
+
+def main():
+ """Main entry point."""
+ parser = argparse.ArgumentParser(description="SAMO Local Development Server")
+ parser.add_argument("--port", type=int, default=None,
+ help="Port to run the server on (default: 8000)")
+ parser.add_argument("--host", default="127.0.0.1",
+ help="Host to bind to (default: 127.0.0.1)")
+ parser.add_argument("--debug", action="store_true",
+ help="Enable debug mode")
+
+ args = parser.parse_args()
+
+ # Handle PORT environment variable with graceful error handling
+ if args.port is None:
+ port_env = os.getenv("PORT", "8000")
+ try:
+ args.port = int(port_env)
+ except ValueError:
+ print(f"โ Invalid PORT value: {port_env!r}. Please provide an integer.")
+ sys.exit(1)
+
+ print("๐ SAMO Local Development Server")
+ print("=" * 40)
+
+ # Validate environment
+ if not validate_environment():
+ sys.exit(1)
+
+ print(f"๐ Serving files from: {WEBSITE_DIR}")
+ print(f"๐ Server URL: http://{args.host}:{args.port}")
+ print("๐ Direct links:")
+ print(f" โข Main page: http://{args.host}:{args.port}/")
+
+ # List available HTML files
+ html_files = list(WEBSITE_DIR.glob("*.html"))
+ for html_file in html_files:
+ if html_file.name != "index.html":
+ url = f"http://{args.host}:{args.port}/{html_file.name}"
+ print(f" โข {html_file.stem.title()}: {url}")
+
+ print(f"๐ฅ Health check: http://{args.host}:{args.port}/health")
+ print("\nPress Ctrl+C to stop the server")
+ print("=" * 40)
+
+ try:
+ app.run(
+ host=args.host,
+ port=args.port,
+ debug=args.debug,
+ threaded=True
+ )
+ except KeyboardInterrupt:
+ print("\n๐ Server stopped by user")
+ except Exception as e:
+ print(f"โ Server error: {e}")
+ sys.exit(1)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/deployment/local/start-simple.sh b/deployment/local/start-simple.sh
new file mode 100755
index 000000000..1c76a39fe
--- /dev/null
+++ b/deployment/local/start-simple.sh
@@ -0,0 +1,101 @@
+#!/usr/bin/env bash
+# Start simple local development server
+
+# Enable strict bash options for fail-fast behavior
+set -euo pipefail
+IFS=$'\n\t'
+
+# Change to script's directory for location independence
+cd "$(dirname "$0")"
+
+echo "๐ STARTING SIMPLE LOCAL DEVELOPMENT SERVER"
+echo "==========================================="
+
+# Check if Python 3 is available
+if ! command -v python3 >/dev/null 2>&1; then
+ echo "โ Error: python3 not found in PATH"
+ echo "Please install Python 3 and try again"
+ exit 127
+fi
+
+echo "โ
Python 3 found: $(python3 --version)"
+
+# Check if requirements file exists
+if [ ! -f requirements-simple.txt ]; then
+ echo "โ Error: requirements-simple.txt not found"
+ echo "Expected location: $(pwd)/requirements-simple.txt"
+ exit 1
+fi
+
+echo "๐ฆ Installing minimal dependencies..."
+
+# Determine if we're in a virtual environment
+if [ -z "${VIRTUAL_ENV:-}" ]; then
+ echo "๐ง Installing dependencies for user (not in virtual environment)"
+ USER_FLAG="--user"
+else
+ echo "๐ง Installing dependencies in virtual environment: $VIRTUAL_ENV"
+ USER_FLAG=""
+fi
+
+# Install dependencies
+if ! python3 -m pip install $USER_FLAG -r requirements-simple.txt; then
+ echo "โ Failed to install dependencies"
+ echo "You may need to run: python3 -m pip install --upgrade pip"
+ exit 1
+fi
+
+echo "โ
Dependencies installed successfully"
+
+# Get port from environment or use default
+PORT="${PORT:-8000}"
+
+# Check if port is available (tries netstat, lsof, or ss; may not be universally reliable)
+if command -v netstat >/dev/null 2>&1; then
+ if netstat -an | grep -q ":$PORT "; then
+ echo "โ ๏ธ Warning: Port $PORT appears to be in use"
+ echo "You can set a different port with: PORT=8001 $0"
+ fi
+elif command -v lsof >/dev/null 2>&1; then
+ if lsof -iTCP:"$PORT" -sTCP:LISTEN -Pn | grep -q LISTEN; then
+ echo "โ ๏ธ Warning: Port $PORT appears to be in use"
+ echo "You can set a different port with: PORT=8001 $0"
+ fi
+elif command -v ss >/dev/null 2>&1; then
+ if ss -ltn | grep -q ":$PORT "; then
+ echo "โ ๏ธ Warning: Port $PORT appears to be in use"
+ echo "You can set a different port with: PORT=8001 $0"
+ fi
+else
+ echo "โน๏ธ Port availability check skipped: no suitable tool (netstat, lsof, ss) found."
+fi
+
+echo "๐ Starting simple development server..."
+echo "๐ Serving website files with CORS enabled"
+echo "๐ Server will be available at: http://localhost:${PORT}"
+echo ""
+echo "Available pages:"
+echo " โข Main page: http://localhost:${PORT}/"
+
+# Check for HTML files in website directory
+WEBSITE_DIR="../../website"
+if [ -d "$WEBSITE_DIR" ]; then
+ for html_file in "$WEBSITE_DIR"/*.html; do
+ if [ -f "$html_file" ]; then
+ filename=$(basename "$html_file")
+ if [ "$filename" != "index.html" ]; then
+ page_name=$(basename "$filename" .html)
+ echo " โข ${page_name^}: http://localhost:${PORT}/${filename}"
+ fi
+ fi
+ done
+fi
+
+echo " โข Health check: http://localhost:${PORT}/health"
+echo ""
+echo "Press Ctrl+C to stop the server"
+echo "==========================================="
+echo ""
+
+# Start the server
+exec python3 simple_server.py --port "${PORT}"