Spaces:
Sleeping
Sleeping
Create application.py
Browse files- application.py +28 -0
application.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
# Set page title and header
|
5 |
+
st.set_page_config(page_title="Text Summarizer", page_icon=":memo:")
|
6 |
+
st.header("Text Summarizer using Arjun9/bart_samsum")
|
7 |
+
|
8 |
+
# Load model and tokenizer
|
9 |
+
model_name = "Arjun9/bart_samsum"
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
12 |
+
|
13 |
+
# Create text input area
|
14 |
+
input_text = st.text_area("Enter the text you want to summarize:", "")
|
15 |
+
|
16 |
+
# Create a function to generate summary
|
17 |
+
def generate_summary(text):
|
18 |
+
inputs = tokenizer.encode_plus(text, return_tensors="pt", max_length=512, truncation=True)
|
19 |
+
outputs = model.generate(inputs["input_ids"], num_beams=4, max_length=128, early_stopping=True)
|
20 |
+
summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
21 |
+
return summary
|
22 |
+
|
23 |
+
# Display summary if input text is provided
|
24 |
+
if input_text:
|
25 |
+
summary = generate_summary(input_text)
|
26 |
+
st.write("**Summary:**", summary)
|
27 |
+
|
28 |
+
streamlit run app.py
|