CoolFace
Apppublic

MaiSlim/pathlet-api

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
index.py111 linesDownload Raw Back to api
1from flask import Flask, request, jsonify2import sys3import os4 5# Add the backend directory to the Python path6backend_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'backend'))7sys.path.insert(0, backend_path)8 9from backend.services.hugging_face import get_possible_ascendants10from backend.services.numerology import calculate_numerology11from backend.services.human_design import calculate_human_design12from backend.utils.validators import validate_request_data13 14app = Flask(__name__)15 16def assign_birth_time(selected_ascendant):17    """18    Assign estimated birth time based on selected ascendant.19    20    Args:21        selected_ascendant (str): Selected ascendant sign22    23    Returns:24        str: Estimated birth time range25    """26    ascendant_time_ranges = {27        "Aries": "04:00 AM - 06:00 AM",28        "Taurus": "06:00 AM - 08:00 AM",29        "Gemini": "08:00 AM - 10:00 AM",30        "Cancer": "10:00 AM - 12:00 PM",31        "Leo": "12:00 PM - 02:00 PM",32        "Virgo": "02:00 PM - 04:00 PM",33        "Libra": "04:00 PM - 06:00 PM",34        "Scorpio": "06:00 PM - 08:00 PM",35        "Sagittarius": "08:00 PM - 10:00 PM",36        "Capricorn": "10:00 PM - 12:00 AM",37        "Aquarius": "12:00 AM - 02:00 AM",38        "Pisces": "02:00 AM - 04:00 AM"39    }40    return ascendant_time_ranges.get(selected_ascendant, "Unknown Time Range")41 42@app.route('/')43def home():44    """45    Home route to confirm API is running.46    47    Returns:48        JSON response with welcome message49    """50    return jsonify({"message": "Pathlet API is running! Use the available endpoints."})51 52@app.route('/get_ascendants', methods=['POST'])53def get_ascendants():54    """55    Endpoint to estimate possible ascendant signs.56    57    Returns:58        JSON response with possible ascendants or error59    """60    data = request.json61    is_valid, error_message = validate_request_data(data)62    63    if not is_valid:64        return jsonify({"error": error_message}), 40065    66    birth_date = data.get("birth_date")67    birth_location = data.get("birth_location")68    69    ascendants = get_possible_ascendants(birth_date, birth_location)70    return jsonify({71        "possible_ascendants": ascendants,72        "instructions": "Review the listed Ascendants and choose the one that resonates most with you."73    })74 75@app.route('/calculate_all', methods=['POST'])76def calculate_all():77    """78    Comprehensive endpoint to calculate all insights.79    80    Returns:81        JSON response with various insights or error82    """83    data = request.json84    is_valid, error_message = validate_request_data(data)85    86    if not is_valid:87        return jsonify({"error": error_message}), 40088    89    birth_date = data.get("birth_date")90    birth_time = data.get("birth_time", "")91    birth_location = data.get("birth_location")92    93    # If no birth time and an ascendant is selected, estimate time94    if not birth_time and "selected_ascendant" in data:95        birth_time = assign_birth_time(data["selected_ascendant"])96    97    human_design = calculate_human_design(birth_date, birth_time, birth_location)98    numerology = calculate_numerology(birth_date)99    100    return jsonify({101        "human_design": human_design,102        "numerology": numerology,103        "birth_time": birth_time104    })105 106def handler(event, context):107    """108    Vercel serverless function handler109    """110    return app111