Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
from sentence_transformers import SentenceTransformer
|
4 |
+
|
5 |
+
# Load the models
|
6 |
+
embedding_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
7 |
+
summarization_model_name = 'facebook/bart-large-cnn'
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(summarization_model_name)
|
9 |
+
summarization_model = AutoModelForSeq2SeqLM.from_pretrained(summarization_model_name)
|
10 |
+
|
11 |
+
# Define the summarization function
|
12 |
+
def summarize_document(document):
|
13 |
+
inputs = tokenizer(document, return_tensors='pt', max_length=1024, truncation=True)
|
14 |
+
summary_ids = summarization_model.generate(inputs['input_ids'], max_length=150, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
|
15 |
+
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
16 |
+
|
17 |
+
# Streamlit app
|
18 |
+
st.title("Content Summarizer")
|
19 |
+
st.write("Enter a document below to get a summary.")
|
20 |
+
|
21 |
+
document = st.text_area("Document")
|
22 |
+
|
23 |
+
if st.button("Summarize"):
|
24 |
+
if document:
|
25 |
+
with st.spinner('Summarizing...'):
|
26 |
+
summary = summarize_document(document)
|
27 |
+
st.write("**Summary:**")
|
28 |
+
st.write(summary)
|
29 |
+
else:
|
30 |
+
st.write("Please enter a document to summarize.")
|