Spaces:
Sleeping
Sleeping
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer | |
from flask import Flask, request, jsonify | |
app = Flask(__name__) | |
# Load the fine-tuned model and tokenizer | |
model_path = '/content/drive/MyDrive/ahsan' # Replace with the path to your model | |
model = AutoModelForSeq2SeqLM.from_pretrained(model_path) | |
tokenizer = AutoTokenizer.from_pretrained(model_path) | |
summarizer = pipeline("summarization", model=model, tokenizer=tokenizer) | |
def summarize(): | |
data = request.json | |
input_text = data.get('text', '') | |
summary = summarizer(input_text, max_length=50, min_length=20, length_penalty=2.0) | |
return jsonify({"summary": summary[0]['summary_text']}) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=5000) | |