ZennyKenny commited on
Commit
d88ec40
·
verified ·
1 Parent(s): 9fe4dba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -2,38 +2,43 @@ import gradio as gr
2
  import torch
3
  from transformers import pipeline
4
 
5
- # Load models
6
- transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=0 if torch.cuda.is_available() else -1)
7
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
 
 
 
 
 
 
 
8
 
9
  # Function to process audio
10
  def process_audio(audio_file):
11
- # Step 1: Transcribe audio
12
- transcription = transcriber(audio_file)["text"]
13
-
14
- # Step 2: Summarize transcription
15
- summary = summarizer(transcription, max_length=50, min_length=10, do_sample=False)[0]["summary_text"]
16
-
17
- return transcription, summary
 
18
 
19
  # Gradio Interface with Horizontal Layout
20
  with gr.Blocks() as interface:
21
  with gr.Row():
22
- # Upload button on the left
23
  with gr.Column():
24
  audio_input = gr.Audio(type="filepath", label="Upload Audio File")
25
  process_button = gr.Button("Process Audio")
26
- # Output text box on the right
27
  with gr.Column():
28
  transcription_output = gr.Textbox(label="Full Transcription", lines=10)
29
  summary_output = gr.Textbox(label="Summary", lines=5)
30
 
31
- # Link the button to the function
32
  process_button.click(
33
  process_audio,
34
  inputs=[audio_input],
35
  outputs=[transcription_output, summary_output]
36
  )
37
 
38
- # Launch the interface with SSR disabled and optional public sharing
39
- interface.launch
 
2
  import torch
3
  from transformers import pipeline
4
 
5
+ # Check if GPU is available; fallback to CPU if not
6
+ device = 0 if torch.cuda.is_available() else -1
7
+
8
+ try:
9
+ # Load models with error handling
10
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
11
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
12
+ except Exception as e:
13
+ print(f"Error loading models: {e}")
14
+ raise
15
 
16
  # Function to process audio
17
  def process_audio(audio_file):
18
+ try:
19
+ # Transcribe the audio
20
+ transcription = transcriber(audio_file)["text"]
21
+ # Summarize the transcription
22
+ summary = summarizer(transcription, max_length=50, min_length=10, do_sample=False)[0]["summary_text"]
23
+ return transcription, summary
24
+ except Exception as e:
25
+ return f"Error processing audio: {e}", ""
26
 
27
  # Gradio Interface with Horizontal Layout
28
  with gr.Blocks() as interface:
29
  with gr.Row():
 
30
  with gr.Column():
31
  audio_input = gr.Audio(type="filepath", label="Upload Audio File")
32
  process_button = gr.Button("Process Audio")
 
33
  with gr.Column():
34
  transcription_output = gr.Textbox(label="Full Transcription", lines=10)
35
  summary_output = gr.Textbox(label="Summary", lines=5)
36
 
 
37
  process_button.click(
38
  process_audio,
39
  inputs=[audio_input],
40
  outputs=[transcription_output, summary_output]
41
  )
42
 
43
+ # Launch the interface with public sharing and SSR disabled
44
+ interface.launch(share=True, ssr=False)