|
from flask import Flask, render_template, request, jsonify |
|
from transformers import pipeline |
|
|
|
app = Flask(__name__) |
|
|
|
|
|
summarizer = pipeline("summarization", model="Ramji/bart-cn-large-medical-summary") |
|
|
|
|
|
@app.route('/') |
|
def home(): |
|
return render_template('index.html') |
|
|
|
|
|
@app.route('/summarize', methods=['POST']) |
|
def summarize(): |
|
data = request.get_json() |
|
text = data.get("text") |
|
if text: |
|
|
|
summary = summarizer(text) |
|
return jsonify({"summary": summary[0]['summary_text']}) |
|
else: |
|
return jsonify({"error": "No text provided"}), 400 |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True) |
|
|