Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,22 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
-
import
|
| 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 |
-
#
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
# Streamlit
|
| 19 |
-
st.title("
|
|
|
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
|
| 24 |
-
# Summarize
|
| 25 |
if st.button("Summarize"):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 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.")
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Load the model and tokenizer from Hugging Face Model Hub
|
| 5 |
+
model_name = "ASaboor/Saboors_Bart_samsum" # Ensure this is correct
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
+
# Streamlit App
|
| 10 |
+
st.title("Summarization App")
|
| 11 |
+
st.write("This app uses a fine-tuned model to summarize text.")
|
| 12 |
|
| 13 |
+
# Text input
|
| 14 |
+
text = st.text_area("Enter text to summarize")
|
| 15 |
|
| 16 |
+
# Summarize button
|
| 17 |
if st.button("Summarize"):
|
| 18 |
+
inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=512, truncation=True)
|
| 19 |
+
summary_ids = model.generate(inputs, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
|
| 20 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 21 |
+
st.write("Summary:")
|
| 22 |
+
st.write(summary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|