Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,11 @@
|
|
| 1 |
-
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
st.write("Please enter the financial text below to generate a concise summary:")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
st.session_state.summarizer = pipeline("summarization", model="human-centered-summarization/financial-summarization-pegasus")
|
| 15 |
-
|
| 16 |
-
# Button to generate summary
|
| 17 |
-
if st.button("Generate Summary"):
|
| 18 |
-
if user_input:
|
| 19 |
-
with st.spinner('Generating summary...'):
|
| 20 |
-
# Generating the summary from the input text
|
| 21 |
-
summary_result = st.session_state.summarizer(user_input, max_length=130, min_length=30, do_sample=False)
|
| 22 |
-
summary = summary_result[0]['summary_text']
|
| 23 |
-
st.write("Summary ๐:")
|
| 24 |
-
st.write(summary)
|
| 25 |
-
else:
|
| 26 |
-
st.error("Please enter some text to generate a summary.")
|
| 27 |
-
|
| 28 |
-
if __name__ == "__main__":
|
| 29 |
-
main()
|
|
|
|
| 1 |
+
from transformers import PegasusTokenizer, PegasusForConditionalGeneration
|
|
|
|
| 2 |
|
| 3 |
+
model_name = "human-centered-summarization/financial-summarization-pegasus"
|
| 4 |
+
tokenizer = PegasusTokenizer.from_pretrained(model_name, use_fast=False)
|
| 5 |
+
model = PegasusForConditionalGeneration.from_pretrained(model_name)
|
|
|
|
| 6 |
|
| 7 |
+
text_to_summarize = "Your text here..."
|
| 8 |
+
input_ids = tokenizer(text_to_summarize, return_tensors="pt").input_ids
|
| 9 |
+
summary_ids = model.generate(input_ids, max_length=60, num_beams=5, early_stopping=True)
|
| 10 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 11 |
+
print(summary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|