Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify, send_from_directory
|
| 2 |
+
from youtube_scraper import get_youtube_info
|
| 3 |
+
from score_model import score_fit
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__, static_folder='.', static_url_path='')
|
| 6 |
+
|
| 7 |
+
@app.route('/')
|
| 8 |
+
def index():
|
| 9 |
+
return send_from_directory('.', 'index.html')
|
| 10 |
+
|
| 11 |
+
@app.route('/api/score', methods=['POST'])
|
| 12 |
+
def api_score():
|
| 13 |
+
data = request.get_json(force=True)
|
| 14 |
+
url = data['url']
|
| 15 |
+
goal = data.get('goal','')
|
| 16 |
+
method = data.get('method','raw')
|
| 17 |
+
info = get_youtube_info(url)
|
| 18 |
+
combined = f"{info['title']} {info['description']}"
|
| 19 |
+
scores = score_fit(combined, goal, method)
|
| 20 |
+
return jsonify({ **info, "scores": scores })
|
| 21 |
+
|
| 22 |
+
if __name__ == '__main__':
|
| 23 |
+
# Use port 7860 on HF Spaces
|
| 24 |
+
app.run(host='0.0.0.0', port=7860, debug=True)
|