Spaces:
Sleeping
Sleeping
File size: 770 Bytes
654cc18 |
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 29 30 |
from flask import Flask, request, jsonify
from transformers import pipeline
app = Flask(__name__)
# Load the summarization pipeline
pipe = pipeline("summarization", model="Falconsai/text_summarization")
@app.route('/')
def home():
return "Text Summarization API is running!"
@app.route('/summarize', methods=['POST'])
def summarize():
try:
data = request.json
text = data.get("text", "")
if not text:
return jsonify({"error": "No text provided"}), 400
summary = pipe(text, max_length=150, min_length=30, do_sample=False)
return jsonify({"summary": summary[0]['summary_text']})
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(debug=True)
|