antfraia commited on
Commit
867943a
·
1 Parent(s): bdc4a5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -1,19 +1,33 @@
1
  import gradio as gr
 
2
  import whisper
3
 
4
- def convert_to_text(audio_path : str) -> str:
5
- model = whisper.load_model("base")
6
- result = model.transcribe(audio_path)
7
- return result["text"]
8
 
9
- audio_input = gr.components.Audio(type="filepath")
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  # Interface for Gradio
12
  iface = gr.Interface(
13
- fn=convert_to_text,
14
  inputs=audio_input,
15
  outputs="text",
16
- title="Free audio transcription",
17
  description="Upload an audio here and get a bullet-point summary of its content.",
18
  theme="Monochrome",
19
  live=True,
 
1
  import gradio as gr
2
+ from transformers import BartTokenizer, BartForConditionalGeneration
3
  import whisper
4
 
5
+ # Initialize the BART model and tokenizer
6
+ MODEL_NAME = "facebook/bart-large-cnn"
7
+ model = BartForConditionalGeneration.from_pretrained(MODEL_NAME)
8
+ tokenizer = BartTokenizer.from_pretrained(MODEL_NAME)
9
 
10
+ def convert_and_summarize(audio_path: str) -> str:
11
+ # Convert audio to text
12
+ whisper_model = whisper.load_model("base")
13
+ result = whisper_model.transcribe(audio_path)
14
+ transcribed_text = result["text"]
15
+
16
+ # Summarize the transcribed text
17
+ inputs = tokenizer([transcribed_text], max_length=1024, truncation=True, return_tensors='pt')
18
+ summary_ids = model.generate(inputs['input_ids'])
19
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
20
+
21
+ return summary
22
+
23
+ audio_input = gr.inputs.Audio(type="filepath")
24
 
25
  # Interface for Gradio
26
  iface = gr.Interface(
27
+ fn=convert_and_summarize,
28
  inputs=audio_input,
29
  outputs="text",
30
+ title="Audio-to-Summarized-Text",
31
  description="Upload an audio here and get a bullet-point summary of its content.",
32
  theme="Monochrome",
33
  live=True,