Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,35 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
8 |
|
9 |
-
# Streamlit
|
10 |
-
st.title("Summarization App")
|
11 |
-
st.write("This app uses a fine-tuned model to summarize text.")
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
|
16 |
-
# Summarize
|
17 |
if st.button("Summarize"):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
import streamlit as st
|
3 |
+
import requests
|
4 |
+
import torch
|
5 |
+
from transformers import pipeline
|
6 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
7 |
+
|
8 |
+
# Replace with your Hugging Face model repository path
|
9 |
+
model_repo_path = 'ASaboor/Saboors_Bart_samsum'
|
10 |
+
|
11 |
+
# Load the model and tokenizer
|
12 |
+
model = BartForConditionalGeneration.from_pretrained(model_repo_path)
|
13 |
+
tokenizer = BartTokenizer.from_pretrained(model_repo_path)
|
14 |
|
15 |
+
# Initialize the summarization pipeline
|
16 |
+
summarizer = pipeline('summarization', model=model,tokenizer=tokenizer)
|
|
|
|
|
17 |
|
18 |
+
# Streamlit app layout
|
19 |
+
st.title("Text Summarization App")
|
|
|
20 |
|
21 |
+
# User input
|
22 |
+
text_input = st.text_area("Enter text to summarize", height=300)
|
23 |
|
24 |
+
# Summarize the text
|
25 |
if st.button("Summarize"):
|
26 |
+
if text_input:
|
27 |
+
with st.spinner("Generating summary..."):
|
28 |
+
try:
|
29 |
+
summary = summarizer(text_input, max_length=150, min_length=30, do_sample=False)
|
30 |
+
st.subheader("Summary")
|
31 |
+
st.write(summary[0]['summary_text'])
|
32 |
+
except Exception as e:
|
33 |
+
st.error(f"Error during summarization: {e}")
|
34 |
+
else:
|
35 |
+
st.warning("Please enter some text to summarize.")
|