legusxyz commited on
Commit
b34a6b9
·
verified ·
1 Parent(s): 2f3f78d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -13,8 +13,19 @@ app = FastAPI()
13
  # Load the Whisper model once during startup
14
  device = 0 if torch.cuda.is_available() else -1 # Use GPU if available, otherwise CPU
15
  # asr_pipeline = pipeline(model="openai/whisper-small", device=device) # Initialize Whisper model
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- asr_pipeline = pipeline( model="openai/whisper-small", device=device, language="pt")
18
 
19
  # Basic GET endpoint
20
  @app.get("/")
 
13
  # Load the Whisper model once during startup
14
  device = 0 if torch.cuda.is_available() else -1 # Use GPU if available, otherwise CPU
15
  # asr_pipeline = pipeline(model="openai/whisper-small", device=device) # Initialize Whisper model
16
+ # asr_pipeline = pipeline( model="openai/whisper-small", device=device, language="pt")
17
+
18
+ # Load model and processor
19
+ model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
20
+ processor = WhisperProcessor.from_pretrained("openai/whisper-small")
21
+
22
+ # Set forced language to Portuguese (pt)
23
+ forced_language_token_id = processor.tokenizer.convert_tokens_to_ids("<|pt|>")
24
+ model.config.forced_decoder_ids = [[2, forced_language_token_id]] # `2` refers to the decoder start token.
25
+
26
+ # Initialize the pipeline
27
+ asr_pipeline = pipeline(task="automatic-speech-recognition", model=model, processor=processor, device=device)
28
 
 
29
 
30
  # Basic GET endpoint
31
  @app.get("/")