File size: 786 Bytes
596c1a0
 
f310226
596c1a0
fd1d999
 
596c1a0
fd1d999
 
 
 
 
596c1a0
 
 
 
 
 
fd1d999
596c1a0
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)

@app.route('/summarize', methods=['POST'])
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)