Spaces:
Sleeping
Sleeping
ibrahimgiki
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,40 @@
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
if
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
if _name_ == "_main_":
|
24 |
st.set_option('deprecation.showfileUploaderEncoding', False)
|
@@ -32,4 +48,4 @@ if _name_ == "_main_":
|
|
32 |
</style>
|
33 |
""",
|
34 |
unsafe_allow_html=True
|
35 |
-
)
|
|
|
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 = 'ibrahimgiki/facebook_bart_base_new'
|
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)
|
|
|
48 |
</style>
|
49 |
""",
|
50 |
unsafe_allow_html=True
|
51 |
+
)
|