NeonSamurai commited on
Commit
d0f32e1
·
verified ·
1 Parent(s): fa52de9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +115 -104
app.py CHANGED
@@ -1,105 +1,116 @@
1
- import streamlit as st
2
- from transformers import pipeline
3
-
4
- st.set_page_config(page_title="Smart Text Summarizer", layout="centered")
5
- st.markdown(
6
- """
7
- <style>
8
- .main {
9
- background-color: #f7f9fc;
10
- }
11
- .block-container {
12
- padding-top: 2rem;
13
- padding-bottom: 2rem;
14
- }
15
- .stButton>button {
16
- color: white;
17
- font-weight: bold;
18
- border-radius: 0.5rem;
19
- padding: 0.6rem 1.2rem;
20
- }
21
- .stTextArea textarea {
22
- border-radius: 0.5rem;
23
- padding: 1rem;
24
- }
25
- </style>
26
- """,
27
- unsafe_allow_html=True
28
- )
29
-
30
- # Centered title and subtitle
31
- st.markdown(
32
- """
33
- <h1 style='text-align: center; font-weight: 700; margin-bottom: 0.5rem;'>
34
- Smart Text Summarizer 🧠
35
- </h1>
36
- <p style='text-align: center; color: #555; font-size: 18px; margin-top: 0;'>
37
- Generate concise and clear summaries with fine-tuned T5 models
38
- </p>
39
- """,
40
- unsafe_allow_html=True
41
- )
42
-
43
- # Model selection keys (simple)
44
- model_options = {
45
- "T5-Small": "NeonSamurai/summarization_t5_small_v2",
46
- "T5-Base": "NeonSamurai/summarization_cnndaily_t5_base"
47
- }
48
-
49
- model_choice_key = st.selectbox("Choose a model:", list(model_options.keys()))
50
- model_name = model_options[model_choice_key]
51
-
52
- @st.cache_resource
53
- def load_pipeline(model_name):
54
- return pipeline(
55
- "text2text-generation",
56
- model=model_name,
57
- tokenizer=model_name,
58
- max_length=256, # fixed max length
59
- min_length=60,
60
- truncation=True,
61
- do_sample=False
62
- )
63
-
64
- summarizer = load_pipeline(model_name)
65
-
66
- st.subheader("📄 Enter the text to summarize:")
67
- input_text = st.text_area("", height=300, placeholder="Paste or type your text here...")
68
-
69
- if st.button("✨ Generate Summary"):
70
- if not input_text.strip():
71
- st.warning("Please enter some text before summarizing.")
72
- else:
73
- with st.spinner("Summarizing..."):
74
- result = summarizer("summarize: " + input_text)
75
- summary = result[0]["generated_text"]
76
-
77
- st.subheader("🧾 Summary Result")
78
- st.success(summary.strip())
79
-
80
- # Background-Image
81
- st.markdown(
82
- """
83
- <style>
84
- .stApp {
85
- background-image: url("https://cdn-uploads.huggingface.co/production/uploads/673f5e166c2774fcc8a82f0b/tjZJvZGkJMLKhorQFfHML.png");
86
- background-size: cover;
87
- background-position: center;
88
- height: 100vh;
89
- }
90
-
91
- /* Semi-transparent overlay */
92
- .stApp::before {
93
- content: "";
94
- position: absolute;
95
- top: 0;
96
- left: 0;
97
- width: 100%;
98
- height: 100%;
99
- background: rgba(0, 0, 0, 0.4); /* 40% transparency */
100
- z-index: -1;
101
- }
102
- </style>
103
- """,
104
- unsafe_allow_html=True
 
 
 
 
 
 
 
 
 
 
 
105
  )
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ st.set_page_config(page_title="Smart Text Summarizer", layout="centered")
5
+ st.markdown(
6
+ """
7
+ <style>
8
+ .main {
9
+ background-color: #f7f9fc;
10
+ }
11
+ .block-container {
12
+ padding-top: 2rem;
13
+ padding-bottom: 2rem;
14
+ }
15
+ .stButton>button {
16
+ color: white;
17
+ font-weight: bold;
18
+ border-radius: 0.5rem;
19
+ padding: 0.6rem 1.2rem;
20
+ }
21
+ .stTextArea textarea {
22
+ border-radius: 0.5rem;
23
+ padding: 1rem;
24
+ }
25
+ </style>
26
+ """,
27
+ unsafe_allow_html=True
28
+ )
29
+
30
+ # Centered title and subtitle
31
+ st.markdown(
32
+ """
33
+ <h1 style='text-align: center; font-weight: 700; margin-bottom: 0.5rem;'>
34
+ Smart Text Summarizer 🧠
35
+ </h1>
36
+ <p style='text-align: center; color: #555; font-size: 18px; margin-top: 0;'>
37
+ Generate concise and clear summaries with fine-tuned T5 models
38
+ </p>
39
+ """,
40
+ unsafe_allow_html=True
41
+ )
42
+
43
+ # Model selection keys (simple)
44
+ model_options = {
45
+ "T5-Small": "NeonSamurai/summarization_t5_small_v2",
46
+ "T5-Base": "NeonSamurai/summarization_cnndaily_t5_base"
47
+ }
48
+
49
+ model_choice_key = st.selectbox("Choose a model:", list(model_options.keys()))
50
+ model_name = model_options[model_choice_key]
51
+
52
+ @st.cache_resource
53
+ def load_pipeline(model_name):
54
+ return pipeline(
55
+ "text2text-generation",
56
+ model=model_name,
57
+ tokenizer=model_name,
58
+ max_length=256, # fixed max length
59
+ min_length=60,
60
+ truncation=True,
61
+ do_sample=False
62
+ )
63
+
64
+ summarizer = load_pipeline(model_name)
65
+
66
+ st.subheader("📄 Enter the text to summarize:")
67
+ input_text = st.text_area("", height=300, placeholder="Paste or type your text here...")
68
+
69
+ if st.button("✨ Generate Summary"):
70
+ if not input_text.strip():
71
+ st.warning("Please enter some text before summarizing.")
72
+ else:
73
+ with st.spinner("Summarizing..."):
74
+ result = summarizer("summarize: " + input_text)
75
+ summary = result[0]["generated_text"]
76
+
77
+ st.subheader("🧾 Summary Result")
78
+ st.success(summary.strip())
79
+
80
+ # Background-Image
81
+ st.markdown(
82
+ """
83
+ <style>
84
+ .stApp {
85
+ background-image: url("https://cdn-uploads.huggingface.co/production/uploads/673f5e166c2774fcc8a82f0b/tjZJvZGkJMLKhorQFfHML.png");
86
+ background-size: cover;
87
+ background-position: center;
88
+ height: 100vh;
89
+ }
90
+
91
+ /* Semi-transparent overlay */
92
+ .stApp::before {
93
+ content: "";
94
+ position: absolute;
95
+ top: 0;
96
+ left: 0;
97
+ width: 100%;
98
+ height: 100%;
99
+ background: rgba(0, 0, 0, 0.4); /* 40% transparency */
100
+ z-index: -1;
101
+ }
102
+ </style>
103
+ """,
104
+ unsafe_allow_html=True
105
+ )
106
+
107
+ # Footer message
108
+ st.markdown(
109
+ """
110
+ <div class="footer-message">
111
+ ⚠️ This app may run slower on Hugging Face spaces. For a faster experience, please visit:
112
+ <a href="https://summarization-cnndaily-t5.streamlit.app/" target="_blank">https://summarization-cnndaily-t5.streamlit.app/</a>
113
+ </div>
114
+ """,
115
+ unsafe_allow_html=True
116
  )