Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Virtual Environment
venv/
__pycache__/

# Model files
*.pkl
distilbart-cnn-dailymail-finetuned/

# OS files
.DS_Store
48 changes: 47 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def process_and_summarize_list(items): return "(Error: The summarization script
app.secret_key = SECRET_KEY

# --- API & Model Setup ---
API_KEY = os.environ.get('YOUTUBE_API_KEY', 'AIzaSyC4ZwDopo_________Q4ZcB5Gw')
API_KEY = os.environ.get('YOUTUBE_API_KEY', 'AIzaSyBnjFy3_______PHAMEyhD4')
youtube = build("youtube", "v3", developerKey=API_KEY)
# **FIX**: Load the correct advanced model file
model = joblib.load("predictive_view_modelGBR.pkl")
Expand Down Expand Up @@ -214,6 +214,52 @@ def analyzer():
return render_template("index.html", result=result, topic_summary=topic_summary,
categories=list(CATEGORY_MAP.keys()), form_data=form_data)

@app.route('/summarizer', methods=['GET', 'POST'])
def summarizer():
if 'user' not in session:
return redirect(url_for('login'))

error = None
summary_result = None
video_link = '' # To keep the form populated

if request.method == 'POST':
video_link = request.form.get('video_link')
if not video_link:
error = "Please enter a video link."
else:
video_id = get_video_id_from_url(video_link)

if not video_id:
error = "Invalid YouTube video link. Please check the URL."
else:
try:
# 1. Fetch video details using your existing helper
details = get_video_details([video_id])
if not details:
error = "Could not fetch video details. Check the link and API key."
else:
snippet = details[0]['snippet']
title = snippet.get('title', 'N/A')
channel = snippet.get('channelTitle', 'N/A')
description = snippet.get('description', '')

# 2. Summarize using your existing helper
summary = safe_summarize(description)

# 3. Package the results for the template
summary_result = {
'title': title,
'channelTitle': channel,
'summary': summary,
'videoId': video_id
}
except Exception as e:
print(f"Error in /summarizer route: {e}")
error = f"An unexpected error occurred."

return render_template('summarizer.html', summary_result=summary_result, error=error, video_link=video_link)


@app.route('/manual', methods=['GET', 'POST'])
def manual():
Expand Down
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
flask
pandas
numpy
python-dateutil
google-api-python-client
joblib
transformers
# Install torch separately with the appropriate CUDA support for your GPU.
# Example (Windows, CUDA 11.8):
# pip install --index-url https://download.pytorch.org/whl/cu118 torch torchvision torchaudio
# Or CPU-only fallback:
# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
32 changes: 22 additions & 10 deletions summarize_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
# Load the summarizer once. It's recommended to handle model loading gracefully.
# This assumes the model is available at the specified local path.
local_model_path = "./distilbart-cnn-dailymail-finetuned"
# Detect available device: prefer GPU when torch.cuda is available, otherwise fall back to CPU.
try:
# Using device=-1 ensures it runs on CPU, which is more compatible for general use.
summarizer = pipeline("summarization", model=local_model_path, device=-1)
import torch
if torch.cuda.is_available():
device = 0 # first CUDA device for transformers pipeline
print("GPU detected (torch.cuda.is_available=True). Using GPU for summarization.")
else:
device = -1
print("No GPU detected. Using CPU for summarization (device=-1).")
except Exception:
device = -1
print("Could not import torch — defaulting to CPU (device=-1). To enable GPU, install torch with CUDA support.")

try:
summarizer = pipeline("summarization", model=local_model_path, device=device)
except Exception as e:
summarizer = None
print(f"CRITICAL: Could not load the summarization model from '{local_model_path}'. Error: {e}")
Expand All @@ -22,14 +34,14 @@ def clean_text(text):

# --- Specific Platform Link Removal ---
platform_domains = [
'youtube\.com', 'youtu\.be', 'music\.youtube\.com',
'facebook\.com', 'fb\.watch', 'fb\.com',
'instagram\.com',
'twitter\.com', 't\.co',
'spotify\.com', 'open\.spotify\.com',
'music\.apple\.com',
'music\.amazon\.com',
'discord\.gg', 'discord\.com'
r'youtube\.com', r'youtu\.be', r'music\.youtube\.com',
r'facebook\.com', r'fb\.watch', r'fb\.com',
r'instagram\.com',
r'twitter\.com', r't\.co',
r'spotify\.com', r'open\.spotify\.com',
r'music\.apple\.com',
r'music\.amazon\.com',
r'discord\.gg', r'discord\.com'
]
platform_link_pattern = r'https?://(www\.)?(' + '|'.join(platform_domains) + r')\S*'
text = re.sub(platform_link_pattern, '', text, flags=re.IGNORECASE)
Expand Down
Loading