|
import streamlit as st |
|
import transformers |
|
from transformers import pipeline |
|
|
|
|
|
model_map = { |
|
"BART": "pavuluriashwitha/Bart_model", |
|
"T5": "t5-small", |
|
"PEGASUS": "google/pegasus-cnn_dailymail" |
|
} |
|
|
|
|
|
st.markdown("<h1 style='text-align: center;'>Text Summarization App</h1>", unsafe_allow_html=True) |
|
|
|
|
|
mode = st.radio("Modes", ["Paragraph", "Bullet Points", "Custom"], horizontal=True) |
|
length_slider = st.slider("Summary Length", 1, 2, 1, label_visibility="collapsed") |
|
length_label = "Short" if length_slider == 1 else "Long" |
|
st.markdown(f"Summary Length: **{length_label}**") |
|
|
|
|
|
model_choice = st.selectbox("Choose Summarization Model", ["BART", "T5", "PEGASUS"]) |
|
|
|
|
|
col1, col2 = st.columns(2) |
|
|
|
|
|
with col1: |
|
st.markdown("### Enter your text:") |
|
user_input = st.text_area("", height=300, placeholder="Paste your job description or content here...") |
|
|
|
|
|
word_count = len(user_input.split()) |
|
st.markdown(f"**{word_count} words**") |
|
|
|
|
|
if st.button("Summarize", use_container_width=True): |
|
if not user_input.strip(): |
|
st.warning("Please enter text to summarize.") |
|
else: |
|
|
|
summarizer = pipeline("summarization", model=model_map[model_choice]) |
|
|
|
|
|
max_len = 150 if length_label == "Short" else 300 |
|
min_len = 40 |
|
|
|
|
|
summary = summarizer(user_input, max_length=max_len, min_length=min_len, do_sample=False)[0]['summary_text'] |
|
st.session_state["summary"] = summary |
|
|
|
|
|
with col2: |
|
st.markdown("### Summary") |
|
if "summary" in st.session_state: |
|
st.success(st.session_state["summary"]) |
|
summary_words = len(st.session_state["summary"].split()) |
|
st.markdown(f"π 1 sentence β’ {summary_words} words") |
|
st.button("Paraphrase Summary") |
|
st.download_button("π₯ Download Summary", st.session_state["summary"], file_name="summary.txt") |
|
else: |
|
st.info("Your summary will appear here.") |