FrancoisHB commited on
Commit
2a6b055
1 Parent(s): f91d5ee

Commit Test SRT

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -1,15 +1,18 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
3
 
4
- # Function to extract text from SRT-formatted text
5
  # Function to extract text from SRT-formatted text
6
  def extract_text_from_srt_text(srt_text):
7
  lines = srt_text.strip().split("\n\n") # Split by empty lines to separate subtitles
8
  texts = [subtitle.split("\n")[2] for subtitle in lines if subtitle.strip()] # Extract text from the third line of each subtitle
9
  return " ".join(texts)
10
 
11
- # Load summarization pipeline
12
- summarizer = pipeline("summarization")
 
 
 
13
 
14
  # Streamlit app
15
  st.title("SRT Summarization")
@@ -23,10 +26,16 @@ if st.button("Summarize"):
23
  if srt_text_input.strip():
24
  # Extract text from SRT-formatted text
25
  text_to_summarize = extract_text_from_srt_text(srt_text_input)
26
- # Summarize text
27
- summary = summarizer(text_to_summarize, max_length=1500, min_length=10, do_sample=False)
28
- # Display summary
 
 
 
 
29
  st.subheader("Summary:")
30
- st.write(summary[0]["summary_text"])
 
 
31
  else:
32
  st.warning("Please enter some SRT-formatted text.")
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ from heapq import nlargest
4
 
 
5
  # Function to extract text from SRT-formatted text
6
  def extract_text_from_srt_text(srt_text):
7
  lines = srt_text.strip().split("\n\n") # Split by empty lines to separate subtitles
8
  texts = [subtitle.split("\n")[2] for subtitle in lines if subtitle.strip()] # Extract text from the third line of each subtitle
9
  return " ".join(texts)
10
 
11
+ # Function to generate summary from text
12
+ def generate_summary(text, summary_length):
13
+ summarizer = pipeline("summarization")
14
+ summary = summarizer(text, max_length=summary_length, min_length=30, do_sample=False)
15
+ return summary[0]["summary_text"]
16
 
17
  # Streamlit app
18
  st.title("SRT Summarization")
 
26
  if srt_text_input.strip():
27
  # Extract text from SRT-formatted text
28
  text_to_summarize = extract_text_from_srt_text(srt_text_input)
29
+ # Generate summary
30
+ summary = generate_summary(text_to_summarize, 150) # You can adjust the summary length as needed
31
+ # Extract top 4 sentences
32
+ sentences = text_to_summarize.split(". ")
33
+ top_sentences = nlargest(4, sentences, key=len)
34
+ top_subjects = "\n".join(top_sentences)
35
+ # Display summary and top 4 subjects
36
  st.subheader("Summary:")
37
+ st.write(summary)
38
+ st.subheader("Top 4 Subjects:")
39
+ st.write(top_subjects)
40
  else:
41
  st.warning("Please enter some SRT-formatted text.")