-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
27 lines (22 loc) · 872 Bytes
/
Copy pathapp.py
File metadata and controls
27 lines (22 loc) · 872 Bytes
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
from flask import Flask, jsonify, request
from helpers import extract_keywords, query, searchYT
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route("/",)
def index():
return jsonify('Welcome to Frontida'), 200
@app.route("/generateText", methods=["POST"])
def generate():
if request.method == 'POST':
input_text = request.json.get('text')
response, statusCode = query(input_text)
## Parse the response content as JSON
if statusCode == 200:
keywords = extract_keywords(input_text)
youtubeLinks = searchYT(', '.join(keywords))
return jsonify({"generated_text": response,"keywords":keywords, "youtubeLink": youtubeLinks}), statusCode
else:
return jsonify({"unexpected error": response}), statusCode
if __name__ == "__main__":
app.run(debug=False)