Skip to content

Instantly share code, notes, and snippets.

@Kakarot-2000
Last active August 22, 2021 05:41
Show Gist options
  • Save Kakarot-2000/bb24bbbd82770faf67249fdd2e79ea9e to your computer and use it in GitHub Desktop.
Save Kakarot-2000/bb24bbbd82770faf67249fdd2e79ea9e to your computer and use it in GitHub Desktop.
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