dtkne commited on
Commit
a952e20
·
verified ·
1 Parent(s): aef58c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -2,25 +2,39 @@ import gradio as gr
2
  import os
3
  from transformers import pipeline
4
 
5
- # Load ASR pipeline
6
  asr = pipeline(task="automatic-speech-recognition", model="distil-whisper/distil-small.en")
7
 
8
- # Define function to process audio input
9
- def transcribe(audio_file):
 
 
 
10
  if audio_file is None:
11
- return "Error: No audio file provided."
12
-
13
  try:
14
- result = asr(audio_file) # Process audio
15
- return result['text'] # Extract the transcribed text
 
 
 
 
 
 
 
 
16
  except Exception as e:
17
- return f"Error: {str(e)}"
18
 
19
  # Create Gradio interface
20
  iface = gr.Interface(
21
- fn=transcribe,
22
- inputs=gr.Audio(type="filepath"), # Expect an audio file path
23
- outputs="text"
 
 
 
24
  )
25
 
26
  # Get port safely (default to 7860 if not set)
 
2
  import os
3
  from transformers import pipeline
4
 
5
+ # Load ASR (Speech-to-Text) pipeline
6
  asr = pipeline(task="automatic-speech-recognition", model="distil-whisper/distil-small.en")
7
 
8
+ # Load Summarization model
9
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
10
+
11
+ # Function to transcribe and summarize
12
+ def transcribe_and_summarize(audio_file):
13
  if audio_file is None:
14
+ return "Error: No audio file provided.", ""
15
+
16
  try:
17
+ # Transcribe audio
18
+ transcription_result = asr(audio_file)
19
+ transcribed_text = transcription_result['text']
20
+
21
+ # Summarize the transcribed text
22
+ summary_result = summarizer(transcribed_text, max_length=100, min_length=30, do_sample=False)
23
+ summarized_text = summary_result[0]['summary_text']
24
+
25
+ return transcribed_text, summarized_text
26
+
27
  except Exception as e:
28
+ return f"Error: {str(e)}", ""
29
 
30
  # Create Gradio interface
31
  iface = gr.Interface(
32
+ fn=transcribe_and_summarize,
33
+ inputs=gr.Audio(type="filepath"), # Accepts an audio file
34
+ outputs=[
35
+ gr.Textbox(label="Transcribed Text"),
36
+ gr.Textbox(label="Summarized Text")
37
+ ]
38
  )
39
 
40
  # Get port safely (default to 7860 if not set)