ibrahimgiki commited on
Commit
2e1a6db
·
verified ·
1 Parent(s): b96adaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -16
app.py CHANGED
@@ -1,24 +1,40 @@
 
 
 
1
  import streamlit as st
2
- from transformers import pipeline
3
 
4
- # Replace with your actual model URL
5
- model_url = "ibrahimgiki/facebook_bart_base_new"
6
 
7
- # Load the model and tokenizer from Hugging Face
8
- summarizer = pipeline("summarization", model=model_url)
9
 
10
- # Streamlit application
11
- st.title("Text Summarization with BART")
 
 
 
 
 
 
 
 
 
 
12
 
13
- # Text input from the user
14
- user_input = st.text_area("Enter the text to summarize:")
15
 
16
- # If user input is provided, summarize the text
17
- if user_input:
18
- with st.spinner("Summarizing..."):
19
- summary = summarizer(user_input, max_length=130, min_length=30, do_sample=False)
20
- summarized_text = summary[0]['summary_text']
21
- st.text_area("Summary:", summarized_text, height=200)
 
 
 
22
 
23
  if _name_ == "_main_":
24
  st.set_option('deprecation.showfileUploaderEncoding', False)
@@ -32,4 +48,4 @@ if _name_ == "_main_":
32
  </style>
33
  """,
34
  unsafe_allow_html=True
35
- )
 
1
+ import os
2
+ os.system('pip install streamlit transformers torch')
3
+
4
  import streamlit as st
5
+ from transformers import BartTokenizer, BartForConditionalGeneration
6
 
7
+ # Load the model and tokenizer
8
+ model_name = 'ibrahimgiki/facebook_bart_base_new'
9
 
10
+ tokenizer = BartTokenizer.from_pretrained(model_name)
11
+ model = BartForConditionalGeneration.from_pretrained(model_name)
12
 
13
+ def summarize_text(text):
14
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding="longest")
15
+ summary_ids = model.generate(
16
+ inputs["input_ids"],
17
+ max_length=150,
18
+ min_length=30,
19
+ length_penalty=2.0,
20
+ num_beams=4,
21
+ early_stopping=True
22
+ )
23
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
24
+ return summary
25
 
26
+ st.title("Text Summarization with Fine-Tuned Model")
27
+ st.write("Enter text to generate a summary using the fine-tuned summarization model.")
28
 
29
+ text = st.text_area("Input Text", height=200)
30
+ if st.button("Summarize"):
31
+ if text:
32
+ with st.spinner("Summarizing..."):
33
+ summary = summarize_text(text)
34
+ st.success("Summary Generated")
35
+ st.write(summary)
36
+ else:
37
+ st.warning("Please enter some text to summarize.")
38
 
39
  if _name_ == "_main_":
40
  st.set_option('deprecation.showfileUploaderEncoding', False)
 
48
  </style>
49
  """,
50
  unsafe_allow_html=True
51
+ )