File size: 792 Bytes
9b7f448
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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/score', methods=['POST'])
def api_score():
    data    = request.get_json(force=True)
    url     = data['url']
    goal    = data.get('goal','')
    method  = data.get('method','raw')
    info    = get_youtube_info(url)
    combined = f"{info['title']} {info['description']}"
    scores  = score_fit(combined, goal, method)
    return jsonify({ **info, "scores": scores })

if __name__ == '__main__':
    # Use port 7860 on HF Spaces
    app.run(host='0.0.0.0', port=7860, debug=True)