Update app.py
Browse files
app.py
CHANGED
@@ -10,9 +10,26 @@ from fastapi.staticfiles import StaticFiles
|
|
10 |
# Define FastAPI app
|
11 |
app = FastAPI()
|
12 |
|
|
|
13 |
device = 0 if torch.cuda.is_available() else -1
|
14 |
-
|
15 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
# Basic GET endpoint
|
|
|
10 |
# Define FastAPI app
|
11 |
app = FastAPI()
|
12 |
|
13 |
+
# Check if GPU is available
|
14 |
device = 0 if torch.cuda.is_available() else -1
|
15 |
+
|
16 |
+
# Load Whisper model and processor
|
17 |
+
model_name = "openai/whisper-small" # Model name can be changed to other variants
|
18 |
+
model = WhisperForConditionalGeneration.from_pretrained(model_name)
|
19 |
+
processor = WhisperProcessor.from_pretrained(model_name)
|
20 |
+
|
21 |
+
# Set forced_decoder_ids to enforce Portuguese language transcription
|
22 |
+
forced_decoder_ids = processor.get_decoder_prompt_ids(language="portuguese", task="transcribe")
|
23 |
+
model.config.forced_decoder_ids = forced_decoder_ids
|
24 |
+
|
25 |
+
# Initialize the ASR pipeline with the modified model
|
26 |
+
asr_pipeline = pipeline(
|
27 |
+
"automatic-speech-recognition",
|
28 |
+
model=model,
|
29 |
+
processor=processor,
|
30 |
+
device=device
|
31 |
+
)
|
32 |
+
|
33 |
|
34 |
|
35 |
# Basic GET endpoint
|