Ramji's picture
UI
069cfa5 verified
raw
history blame
No virus
844 Bytes
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)
print(summary)
return jsonify({"summary": summary[0]['summary_text']})
else:
return jsonify({"error": "No text provided"}), 400
if __name__ == '__main__':
app.run(debug=True)