Spaces:
Sleeping
Sleeping
Download app.py from AhsanShahid/Text-Summarization: direct link, hf CLI and curl.
- Browser
- Download file 786 Bytes
-
https://huggingface.co/spaces/AhsanShahid/Text-Summarization/resolve/main/app.py
- Command line
-
hf download hf://spaces/AhsanShahid/Text-Summarization/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AhsanShahid/Text-Summarization/resolve/main/app.py
786 Bytes
| 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) | |