Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,29 @@
|
|
1 |
import streamlit as st
|
2 |
-
from streamlit.components.v1 import html
|
3 |
from transformers import BartForConditionalGeneration, BartTokenizer
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
.stApp {
|
10 |
-
%s
|
11 |
-
}
|
12 |
-
</style>
|
13 |
-
""" % style
|
14 |
-
return html(component, height=0)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
summary_ids = model.generate(inputs, max_length=max_length, min_length=max_length//4, length_penalty=2.0, num_beams=4, early_stopping=True)
|
19 |
|
20 |
-
|
21 |
-
return
|
22 |
|
23 |
def main():
|
24 |
-
# Set background style
|
25 |
-
set_background("""
|
26 |
-
background-image: url('https://your-image-url.jpg');
|
27 |
-
background-size: cover;
|
28 |
-
""")
|
29 |
-
|
30 |
-
# Title and description
|
31 |
st.title("Data Summarization")
|
32 |
-
st.write("Enter your data, set the summary length, and click submit.")
|
33 |
-
|
34 |
-
# Text input box
|
35 |
-
data = st.text_area("Enter your Data", height=200)
|
36 |
|
37 |
-
|
38 |
-
max_length = st.slider("Summary Length",
|
39 |
-
|
40 |
-
# Load the pretrained BART model and tokenizer
|
41 |
-
model_name = "facebook/bart-large-cnn"
|
42 |
-
model = BartForConditionalGeneration.from_pretrained(model_name)
|
43 |
-
tokenizer = BartTokenizer.from_pretrained(model_name)
|
44 |
|
45 |
-
# Submit button
|
46 |
if st.button("Submit"):
|
47 |
if not data:
|
48 |
-
st.warning("Please enter some
|
49 |
else:
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
# Display result in a stylized output box
|
54 |
-
st.markdown(
|
55 |
-
f"<div style='background-color:#8c88f9; padding: 10px; border-radius: 10px;'>"
|
56 |
-
f"<h3>Your Summary</h3>"
|
57 |
-
f"<p>{result}</p>"
|
58 |
-
f"</div>",
|
59 |
-
unsafe_allow_html=True,
|
60 |
-
)
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
-
main()
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from transformers import BartForConditionalGeneration, BartTokenizer
|
3 |
|
4 |
+
def summarize_text(data, max_length):
|
5 |
+
model_name = "facebook/bart-large-cnn"
|
6 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
7 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
inputs = tokenizer(data, max_length=max_length, return_tensors="pt", truncation=True)
|
10 |
+
summary_ids = model.generate(inputs["input_ids"])
|
|
|
11 |
|
12 |
+
summary_text = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
13 |
+
return summary_text
|
14 |
|
15 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
st.title("Data Summarization")
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
data = st.text_area("Enter your Data", "")
|
19 |
+
max_length = st.slider("Summary Length", 20, 1000, 200)
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
21 |
if st.button("Submit"):
|
22 |
if not data:
|
23 |
+
st.warning("Please enter some text for summarization.")
|
24 |
else:
|
25 |
+
summary = summarize_text(data, max_length)
|
26 |
+
st.text_area("Your Summary", summary, height=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
if __name__ == "__main__":
|
29 |
+
main()
|