naveenus commited on
Commit
43226f9
·
verified ·
1 Parent(s): 7615c64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -8,17 +8,28 @@ app = Flask(__name__, static_folder='.', static_url_path='')
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)
 
8
  def index():
9
  return send_from_directory('.', 'index.html')
10
 
11
+ # New endpoint: fetch only metadata once
12
+ @app.route('/api/meta', methods=['POST'])
13
+ def api_meta():
14
+ data = request.get_json(force=True)
15
+ url = data['url']
16
+ info = get_youtube_info(url)
17
+ # Return just title & description
18
+ return jsonify({
19
+ "title": info["title"],
20
+ "description": info["description"]
21
+ })
22
+
23
+ # Score endpoint now expects already-fetched title+description
24
  @app.route('/api/score', methods=['POST'])
25
  def api_score():
26
+ data = request.get_json(force=True)
27
+ title = data['title']
28
+ description = data['description']
29
+ goal = data.get('goal','')
30
+ combined = f"{title} {description}"
31
+ scores = score_fit(combined, goal, method='raw')
32
+ return jsonify({"scores": scores})
 
33
 
34
  if __name__ == '__main__':
35
+ app.run(debug=True)