Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,31 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
else:
|
| 12 |
-
# Load the tokenizer and model from Google Drive
|
| 13 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 14 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
|
| 3 |
|
| 4 |
+
# Replace with your model name on Hugging Face Hub
|
| 5 |
+
model_name = "your-username/your-model-name"
|
| 6 |
|
| 7 |
+
# Load the tokenizer and model from Hugging Face Hub
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Streamlit app UI
|
| 12 |
+
st.title("BART Summarization Model")
|
| 13 |
|
| 14 |
+
input_text = st.text_area("Input Text", "Enter text here...")
|
| 15 |
|
| 16 |
+
if st.button("Generate Summary"):
|
| 17 |
+
if not input_text.strip():
|
| 18 |
+
st.warning("Please enter some text to summarize.")
|
| 19 |
+
else:
|
| 20 |
+
# Tokenize and generate summary
|
| 21 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 22 |
+
summary_ids = model.generate(inputs["input_ids"], max_length=150, num_beams=4, early_stopping=True)
|
| 23 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 24 |
+
|
| 25 |
+
# Display the summary
|
| 26 |
+
st.subheader("Generated Summary")
|
| 27 |
+
st.write(summary)
|
| 28 |
|
| 29 |
+
# Optionally, you can add a section to display model information or statistics
|
| 30 |
+
st.sidebar.title("Model Information")
|
| 31 |
+
st.sidebar.write("This app uses a fine-tuned BART model for summarization.")
|