|
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') |
|
|
|
|
|
@app.route('/api/meta', methods=['POST']) |
|
def api_meta(): |
|
data = request.get_json(force=True) |
|
url = data['url'] |
|
info = get_youtube_info(url) |
|
|
|
return jsonify({ |
|
"title": info["title"], |
|
"description": info["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) |