Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
os.system('pip install streamlit transformers torch')
|
| 3 |
|
| 4 |
import streamlit as st
|
| 5 |
-
from transformers import
|
| 6 |
|
| 7 |
-
# Load the
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
tokenizer = BartTokenizer.from_pretrained(model_name)
|
| 11 |
-
model = BartForConditionalGeneration.from_pretrained(model_name)
|
| 12 |
|
| 13 |
def summarize_text(text):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
inputs["input_ids"],
|
| 17 |
-
max_length=150,
|
| 18 |
-
min_length=30,
|
| 19 |
-
length_penalty=2.0,
|
| 20 |
-
num_beams=4,
|
| 21 |
-
early_stopping=True
|
| 22 |
-
)
|
| 23 |
-
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 24 |
-
return summary
|
| 25 |
|
| 26 |
st.title("Text Summarization with Fine-Tuned Model")
|
| 27 |
st.write("Enter text to generate a summary using the fine-tuned summarization model.")
|
|
|
|
| 1 |
+
# import os
|
| 2 |
+
# os.system('pip install streamlit transformers torch')
|
| 3 |
+
|
| 4 |
+
# import streamlit as st
|
| 5 |
+
# from transformers import BartTokenizer, BartForConditionalGeneration
|
| 6 |
+
|
| 7 |
+
# # Load the model and tokenizer
|
| 8 |
+
# model_name = 'facebook/bart-large-cnn'
|
| 9 |
+
|
| 10 |
+
# tokenizer = BartTokenizer.from_pretrained(model_name)
|
| 11 |
+
# model = BartForConditionalGeneration.from_pretrained(model_name)
|
| 12 |
+
|
| 13 |
+
# def summarize_text(text):
|
| 14 |
+
# inputs = tokenizer(text, return_tensors="pt", truncation=True, padding="longest")
|
| 15 |
+
# summary_ids = model.generate(
|
| 16 |
+
# inputs["input_ids"],
|
| 17 |
+
# max_length=150,
|
| 18 |
+
# min_length=30,
|
| 19 |
+
# length_penalty=2.0,
|
| 20 |
+
# num_beams=4,
|
| 21 |
+
# early_stopping=True
|
| 22 |
+
# )
|
| 23 |
+
# summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 24 |
+
# return summary
|
| 25 |
+
|
| 26 |
+
# st.title("Text Summarization with Fine-Tuned Model")
|
| 27 |
+
# st.write("Enter text to generate a summary using the fine-tuned summarization model.")
|
| 28 |
+
|
| 29 |
+
# text = st.text_area("Input Text", height=200)
|
| 30 |
+
# if st.button("Summarize"):
|
| 31 |
+
# if text:
|
| 32 |
+
# with st.spinner("Summarizing..."):
|
| 33 |
+
# summary = summarize_text(text)
|
| 34 |
+
# st.success("Summary Generated")
|
| 35 |
+
# st.write(summary)
|
| 36 |
+
# else:
|
| 37 |
+
# st.warning("Please enter some text to summarize.")
|
| 38 |
+
|
| 39 |
+
# if __name__ == "__main__":
|
| 40 |
+
# st.set_option('deprecation.showfileUploaderEncoding', False)
|
| 41 |
+
# st.markdown(
|
| 42 |
+
# """
|
| 43 |
+
# <style>
|
| 44 |
+
# .reportview-container {
|
| 45 |
+
# flex-direction: row;
|
| 46 |
+
# justify-content: center.
|
| 47 |
+
# }
|
| 48 |
+
# </style>
|
| 49 |
+
# """,
|
| 50 |
+
# unsafe_allow_html=True
|
| 51 |
+
# )
|
| 52 |
import os
|
| 53 |
os.system('pip install streamlit transformers torch')
|
| 54 |
|
| 55 |
import streamlit as st
|
| 56 |
+
from transformers import pipeline
|
| 57 |
|
| 58 |
+
# Load the summarization pipeline
|
| 59 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
def summarize_text(text):
|
| 62 |
+
summary = summarizer(text, max_length=150, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
|
| 63 |
+
return summary[0]['summary_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
st.title("Text Summarization with Fine-Tuned Model")
|
| 66 |
st.write("Enter text to generate a summary using the fine-tuned summarization model.")
|