ASaboor commited on
Commit
02dce0c
1 Parent(s): 24397f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
app.py CHANGED
@@ -1,22 +1,35 @@
 
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)
 
 
 
 
 
 
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.")