RamAnanth1 commited on
Commit
382782b
·
1 Parent(s): 2e9ec14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -3,29 +3,25 @@ import gradio as gr
3
  import os, json
4
  from loguru import logger
5
  import random
6
- import whisper
7
  import torch
8
 
9
  session_token = os.environ.get('SessionToken')
10
  # logger.info(f"session_token_: {session_token}")
11
 
12
- whisper_model = whisper.load_model("medium")
13
 
14
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
15
 
16
- def transcribe(audio):
17
- audio = whisper.load_audio(audio)
18
- audio = whisper.pad_or_trim(audio)
19
-
20
- mel = whisper.log_mel_spectrogram(audio).to(whisper_model.device)
 
21
 
22
- _, probs = whisper_model.detect_language(mel)
23
- translate_options = whisper.DecodingOptions(task="translate", fp16 = False)
24
-
25
- translation = whisper.decode(whisper_model, mel, translate_options)
26
-
27
- print("Translated: " + translation.text)
28
- return translation.text
29
 
30
  def get_response_from_chatbot(text):
31
  try:
 
3
  import os, json
4
  from loguru import logger
5
  import random
6
+ from transformers import pipeline
7
  import torch
8
 
9
  session_token = os.environ.get('SessionToken')
10
  # logger.info(f"session_token_: {session_token}")
11
 
 
12
 
13
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
14
 
15
+ whisper_model = pipeline(
16
+ task="automatic-speech-recognition",
17
+ model="openai/whisper-large-v2",
18
+ chunk_length_s=30,
19
+ device=device,
20
+ )
21
 
22
+ def transcribe(audio):
23
+ text = whisper_model(audio)["text"]
24
+ return text
 
 
 
 
25
 
26
  def get_response_from_chatbot(text):
27
  try: