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