File size: 1,102 Bytes
9b7f448 43226f9 9b7f448 43226f9 9b7f448 43226f9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from flask import Flask, request, jsonify, send_from_directory
from youtube_scraper import get_youtube_info
from score_model import score_fit
app = Flask(__name__, static_folder='.', static_url_path='')
@app.route('/')
def index():
return send_from_directory('.', 'index.html')
# New endpoint: fetch only metadata once
@app.route('/api/meta', methods=['POST'])
def api_meta():
data = request.get_json(force=True)
url = data['url']
info = get_youtube_info(url)
# Return just title & description
return jsonify({
"title": info["title"],
"description": info["description"]
})
# Score endpoint now expects already-fetched title+description
@app.route('/api/score', methods=['POST'])
def api_score():
data = request.get_json(force=True)
title = data['title']
description = data['description']
goal = data.get('goal','')
combined = f"{title} {description}"
scores = score_fit(combined, goal, method='raw')
return jsonify({"scores": scores})
if __name__ == '__main__':
app.run(debug=True)
|