from flask import Flask, request, jsonify
import spacy

app = Flask(__name__)
nlp = spacy.load("en_core_web_sm") # Replace with your trained model

@app.route('/nlp/analyze', methods=['POST'])
def analyze_text():
    data = request.get_json()
    text = data['text']
    doc = nlp(text)

    intent = "unknown" # Default intent
    if "book flight" in text.lower():
      intent = "book_flight"

    entities = {}
    for ent in doc.ents:
        entities[ent.label_] = ent.text

    return jsonify({
        "intent": intent,
        "entities": entities
    })

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')