cfc-tech commited on
Commit
fa63d63
·
verified ·
1 Parent(s): b8c5f6f

Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -3,11 +3,9 @@ from pytube import YouTube
3
  from moviepy.editor import *
4
  import torch
5
  from transformers import Wav2Vec2ForCTC, Wav2Vec2CTCTokenizer, pipeline, logging
6
- from transformers import pipeline
7
  import librosa
8
 
9
-
10
- # Suppress warnings from transformers
11
  logging.set_verbosity_error()
12
 
13
  # Streamlit interface setup
@@ -48,22 +46,26 @@ if st.button('Summarize'):
48
  predicted_ids = torch.argmax(logits, dim=-1)
49
 
50
  # Decode the speech
51
- transcription = tokenizer.decode(predicted_ids[0])
52
 
53
- # Show progress
54
- st.progress(75)
 
 
55
 
56
- # Summarization
57
- summarizer = pipeline("summarization")
58
- summary = summarizer(transcription, max_length=130, min_length=30, do_sample=False)
59
 
60
- # Display the summary
61
- st.success("Done!")
62
- st.write("### Summary:")
63
- st.write(summary[0]['summary_text'])
64
 
65
- # Final progress
66
- st.progress(100)
 
 
67
 
68
  except Exception as e:
69
  st.error(f"An error occurred: {e}")
 
3
  from moviepy.editor import *
4
  import torch
5
  from transformers import Wav2Vec2ForCTC, Wav2Vec2CTCTokenizer, pipeline, logging
 
6
  import librosa
7
 
8
+ # Suppress warnings from transformers to clean up the output
 
9
  logging.set_verbosity_error()
10
 
11
  # Streamlit interface setup
 
46
  predicted_ids = torch.argmax(logits, dim=-1)
47
 
48
  # Decode the speech
49
+ transcription = tokenizer.batch_decode(predicted_ids, skip_special_tokens=True)[0] # Ensure transcription is a single string
50
 
51
+ # Ensure transcription is a string and not empty
52
+ if isinstance(transcription, str) and transcription.strip():
53
+ # Show progress
54
+ st.progress(75)
55
 
56
+ # Summarization
57
+ summarizer = pipeline("summarization")
58
+ summary = summarizer(transcription, max_length=130, min_length=30, do_sample=False)
59
 
60
+ # Display the summary
61
+ st.success("Done!")
62
+ st.write("### Summary:")
63
+ st.write(summary[0]['summary_text'])
64
 
65
+ # Final progress
66
+ st.progress(100)
67
+ else:
68
+ st.error("Could not transcribe audio or transcription is empty.")
69
 
70
  except Exception as e:
71
  st.error(f"An error occurred: {e}")