FrancoisHB commited on
Commit
a8924ed
1 Parent(s): 5f56b80

Commit Test SRT

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -1,31 +1,31 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Function to extract text from SRT file
5
- # Function to extract text from SRT file
6
- def extract_text_from_srt(srt_text):
7
  lines = srt_text.strip().split("\n")
8
- # Extract text content from SRT
9
- texts = [line.split("\n")[2] for line in lines if len(line.split("\n")) > 2 and not line.startswith("0")]
10
  return " ".join(texts)
11
 
12
-
13
  # Load summarization pipeline
14
  summarizer = pipeline("summarization")
15
 
16
  # Streamlit app
17
  st.title("SRT Summarization")
18
 
19
- # Text area for user to upload SRT file
20
- srt_file = st.file_uploader("Upload SRT file", type=["srt"])
21
 
22
- if srt_file is not None:
23
- # Read uploaded SRT file
24
- srt_text = srt_file.read().decode("utf-8")
25
- # Extract text from SRT
26
- text_to_summarize = extract_text_from_srt(srt_text)
27
- # Summarize text
28
- summary = summarizer(text_to_summarize, max_length=150, min_length=30, do_sample=False)
29
- # Display summary
30
- st.subheader("Summary:")
31
- st.write(summary[0]["summary_text"])
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Function to extract text from SRT-formatted text
5
+ def extract_text_from_srt_text(srt_text):
 
6
  lines = srt_text.strip().split("\n")
7
+ texts = [line.split("\n")[2] for line in lines if not line.startswith("0")]
 
8
  return " ".join(texts)
9
 
 
10
  # Load summarization pipeline
11
  summarizer = pipeline("summarization")
12
 
13
  # Streamlit app
14
  st.title("SRT Summarization")
15
 
16
+ # Text area for user to input SRT-formatted text
17
+ srt_text_input = st.text_area("Paste SRT-formatted text here:")
18
 
19
+ # Button to trigger summarization
20
+ if st.button("Summarize"):
21
+ # Check if text area is not empty
22
+ if srt_text_input.strip():
23
+ # Extract text from SRT-formatted text
24
+ text_to_summarize = extract_text_from_srt_text(srt_text_input)
25
+ # Summarize text
26
+ summary = summarizer(text_to_summarize, max_length=1500, min_length=10, do_sample=False)
27
+ # Display summary
28
+ st.subheader("Summary:")
29
+ st.write(summary[0]["summary_text"])
30
+ else:
31
+ st.warning("Please enter some SRT-formatted text.")