from flask import Flask, render_template, request
from models import WordFrequencyModel

app = Flask(__name__)
app.config['SECRET_KEY'] = 'your-secret-key'

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/count', methods=['POST'])
def count_words():
    text = request.form.get('text', '').lower()
    model = WordFrequencyModel()
    top_words = model.get_top_n_words(text, 10)
    return render_template('index.html', top_words=top_words)

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