File size: 821 Bytes
96412da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request, jsonify
from transformers import pipeline

app = Flask(__name__)

# Load the Hugging Face summarization model
summarizer = pipeline("summarization", model="Ramji/bart-cn-large-medical-summary")

# Route to display the home page
@app.route('/')
def home():
    return render_template('index.html')

# Route to handle the summarization request
@app.route('/summarize', methods=['POST'])
def summarize():
    data = request.get_json()  # Get the data from the client-side request
    text = data.get("text")
    if text:
        # Perform summarization
        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)