Spaces:
Sleeping
Sleeping
File size: 684 Bytes
2701772 7507a36 524f780 7507a36 cc12c1a 524f780 cc12c1a 524f780 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import os
from transformers import pipeline
# Set custom cache directory to avoid permission issues
os.environ["TRANSFORMERS_CACHE"] = "/app/cache"
# Load the model with TensorFlow weights if PyTorch version is unavailable
summarizer = pipeline("summarization", model="t5-base", from_tf=True)
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/summarize", methods=["POST"])
def summarize():
data = request.json
text = data.get("text", "")
summary = summarizer(text, max_length=150, min_length=30, do_sample=False)
return jsonify({"summary": summary[0]["summary_text"]})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)
|