AlexMo commited on
Commit
fd9ff9b
1 Parent(s): a658f1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -18
app.py CHANGED
@@ -9,6 +9,22 @@ model = whisper.load_model("base")
9
  # model = pipeline(model="AlexMo/FIFA_WC22_WINNER_LANGUAGE_MODEL")
10
  summarizer = pipeline("summarization")
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  def getAudio(url):
14
  link = YouTube(url)
@@ -36,23 +52,45 @@ def getSummary(article):
36
 
37
 
38
  with gr.Blocks() as demo:
39
- gr.Markdown(
40
- "<h1><center>Free Fast YouTube URL Video to Text using <a href=https://openai.com/blog/whisper/ target=_blank>OpenAI's Whisper</a> Model</center></h1>")
41
- gr.Markdown(
42
- "<center>Enter the link of any YouTube video to generate a text transcript of the video and then create a summary of the video transcript.</center>")
43
- gr.Markdown(
44
- "<center><b>'Whisper is a neural net that approaches human level robustness and accuracy on English speech recognition.'</b></center>")
45
- gr.Markdown(
46
- "<center>Generating the transcript takes 5-10 seconds per minute of the video</center>")
47
-
48
- input_text_url = gr.Textbox(placeholder='Youtube video URL', label='URL')
49
- result_button_transcribe = gr.Button('1. Transcribe')
50
- output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
51
-
52
- result_button_summary = gr.Button('2. Create Summary')
53
- output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary')
54
-
55
- result_button_transcribe.click(getText, inputs=input_text_url, outputs=output_text_transcribe)
56
- result_button_summary.click(getSummary, inputs=output_text_transcribe, outputs=output_text_summary)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  demo.launch(debug=True)
 
9
  # model = pipeline(model="AlexMo/FIFA_WC22_WINNER_LANGUAGE_MODEL")
10
  summarizer = pipeline("summarization")
11
 
12
+ def transcribe(microphone, file_upload):
13
+ warn_output = ""
14
+ if (microphone is not None) and (file_upload is not None):
15
+ warn_output = (
16
+ "WARNING: You've uploaded an audio file and used the microphone. "
17
+ "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
18
+ )
19
+
20
+ elif (microphone is None) and (file_upload is None):
21
+ return "ERROR: You have to either use the microphone or upload an audio file"
22
+
23
+ file = microphone if microphone is not None else file_upload
24
+
25
+ text = summarizer(file)["text"]
26
+
27
+ return warn_output + text
28
 
29
  def getAudio(url):
30
  link = YouTube(url)
 
52
 
53
 
54
  with gr.Blocks() as demo:
55
+ gr.HTML(
56
+ """
57
+ <div style="text-align: center; max-width: 500px; margin: 0 auto;">
58
+ <div>
59
+ <h1>Dutch whisperer</h1>
60
+ </div>
61
+ <p style="margin-bottom: 10px; font-size: 94%">
62
+ Summarize audio files, mic input or Youtube videos using OpenAI's Whisper
63
+ </p>
64
+ </div>
65
+ """
66
+ )
67
+ with gr.Tab('Get a summary from your own mic or audio file'):
68
+ with gr.Row():
69
+ gr.Interface(
70
+ fn=transcribe,
71
+ inputs=[
72
+ gr.inputs.Audio(source="microphone", type="filepath", optional=True),
73
+ gr.inputs.Audio(source="upload", type="filepath", optional=True),
74
+ ],
75
+ outputs="text",
76
+ layout="horizontal",
77
+ theme="huggingface",
78
+ title="Dutch whisper: Summarize Audio",
79
+ description=(
80
+ "Transcribe and summarize."
81
+ ),
82
+ allow_flagging="never",
83
+ )
84
+ with gr.Tab('Summary of Youtube video'):
85
+ with gr.Row():
86
+ input_text_url = gr.Textbox(placeholder='Youtube video URL', label='URL')
87
+ result_button_transcribe = gr.Button('1. Transcribe')
88
+ output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
89
+
90
+ result_button_summary = gr.Button('2. Create Summary')
91
+ output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary')
92
+
93
+ result_button_transcribe.click(getText, inputs=input_text_url, outputs=output_text_transcribe)
94
+ result_button_summary.click(getSummary, inputs=output_text_transcribe, outputs=output_text_summary)
95
 
96
  demo.launch(debug=True)