AI Text Summarizer: Ek Smart Tool Jo Badi Text Ko Short Mein Convert Kare!
Demo :
Click Video πππ
✅ Features:
- AI-Powered Summarization
- Instant Results
- Simple & Fast
π Folder Structure:
π AI_Text_Summarizer/
│── π app.py
│── π requirements.txt
│── π templates/
│ ├── π index.html
│── π static/
│ ├── π style.css
Install Required Libraries
cmd : pip install flask transformers torch
Code :
Python Backend (app.py)
from flask import Flask, render_template, requestimport torchfrom transformers import pipelineapp = Flask(__name__)# Check if PyTorch is availableif not torch.cuda.is_available():print("Warning: CUDA (GPU) not available, using CPU.")# Load Pre-Trained Summarization Modeltry:summarizer = pipeline("summarization", device=0 if torch.cuda.is_available() else -1)except Exception as e:print(f"Error loading model: {e}")summarizer = None # Model load failure handling@app.route("/", methods=["GET", "POST"])def index():summary = ""if request.method == "POST":input_text = request.form["input_text"]if input_text and summarizer:try:summary = summarizer(input_text, max_length=150, min_length=30, do_sample=False)[0]['summary_text']except Exception as e:summary = f"Error summarizing text: {e}"return render_template("index.html", summary=summary)if __name__ == "__main__":app.run(debug=True)
HTML Frontend (templates/index.html)
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI Text Summarizer</title><link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"></head><body><h2>AI-Powered Text Summarizer</h2><form method="post"><textarea name="input_text" rows="5" placeholder="Yahan text paste karo..."></textarea><button type="submit">Summarize</button></form>{% if summary %}<h3>Summary:</h3><p>{{ summary }}</p>{% endif %}</body></html>
CSS Styling (static/style.css)
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
background-color: #f4f4f4;
}
textarea {
width: 80%;
padding: 10px;
margin: 10px;
}
button {
padding: 10px 20px;
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
}
π― Run The Code :
python app.py
Comments
Post a Comment