Spaces:
Sleeping
Sleeping
requirements.txt
Browse filesstreamlit
transformers
torch
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
st.set_page_config(page_title="LLM Text Summarizer", layout="centered")
|
5 |
+
st.title("LLM-Powered Text Summarizer")
|
6 |
+
st.markdown("This app summarizes long texts using a Hugging Face transformer model (`facebook/bart-large-cnn`).")
|
7 |
+
|
8 |
+
@st.cache_resource
|
9 |
+
def load_model():
|
10 |
+
return pipeline("summarization", model="facebook/bart-large-cnn")
|
11 |
+
|
12 |
+
summarizer = load_model()
|
13 |
+
|
14 |
+
text = st.text_area("Enter text to summarize", height=300)
|
15 |
+
|
16 |
+
if st.button("Summarize"):
|
17 |
+
if len(text.strip()) == 0:
|
18 |
+
st.warning("Please enter some text first.")
|
19 |
+
else:
|
20 |
+
word_count = len(text.split())
|
21 |
+
|
22 |
+
if word_count > 1300:
|
23 |
+
max_tokens = 1300
|
24 |
+
elif word_count > 300:
|
25 |
+
max_tokens = 350
|
26 |
+
else:
|
27 |
+
max_tokens = 100
|
28 |
+
|
29 |
+
with st.spinner("Generating summary..."):
|
30 |
+
summary = summarizer(
|
31 |
+
text,
|
32 |
+
max_length=max_tokens,
|
33 |
+
min_length=int(max_tokens * 0.5),
|
34 |
+
do_sample=False
|
35 |
+
)
|
36 |
+
st.subheader("Summary:")
|
37 |
+
st.success(summary[0]['summary_text'])
|