File size: 1,046 Bytes
a4bba1a 4c84960 a4bba1a 4c84960 a4bba1a 4c84960 a4bba1a 4c84960 a4bba1a 4c84960 a4bba1a 4c84960 a4bba1a 4c84960 a4bba1a |
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 28 29 30 31 32 33 34 |
from flask import Flask, request
from textblob import TextBlob
flask_app = Flask(__name__)
@flask_app.route("/text/summarize", methods=["POST"])
def summarize():
text = request.json.get("text")
return {"summary": TextBlob(text).summarize()}
@flask_app.route("/text/extract", methods=["POST"])
def extract():
text = request.json.get("text")
return {"keywords": TextBlob(text).keywords}
@flask_app.route("/text/paraphrase", methods=["POST"])
def paraphrase():
text = request.json.get("text")
return {"paraphrase": TextBlob(text).correct()}
@flask_app.route("/text/grammar", methods=["POST"])
def grammar():
text = request.json.get("text")
return {"errors": TextBlob(text).spellcheck()}
@flask_app.route("/chat", methods=["POST"])
def chat():
prompt = request.json.get("prompt")
# TODO: create chatting logic
return {"response": f"prompt: {prompt}\nresponse: Still working on Text Generation logic, thanks for the patience!"}
if __name__ == "__main__":
flask_app.run(host="0.0.0.0", port=7860)
|