Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
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)
|