Last active
August 22, 2021 05:41
-
-
Save Kakarot-2000/bb24bbbd82770faf67249fdd2e79ea9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from flask import Flask, request, jsonify, Response | |
import nlpcloud | |
from flask_cors import CORS, cross_origin | |
import trafilatura | |
from dotenv import load_dotenv | |
import os | |
app = Flask(__name__) | |
CORS(app, support_credentials=True) | |
load_dotenv() | |
# Get the API token from the .env file. | |
TOKEN = os.getenv("token") | |
client = nlpcloud.Client( | |
"bart-large-cnn", TOKEN) | |
@app.route('/getSummary', methods=['POST']) | |
@cross_origin(supports_credentials=True) | |
def getSummary(): | |
req = request.get_json() | |
downloaded = trafilatura.fetch_url(req['url']) | |
text = trafilatura.extract(downloaded) | |
response = client.summarization(text[:1000]) | |
resp = Response(response['summary_text']) | |
return resp | |
@app.route('/') | |
def home(): | |
return "Hello!!" | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment