Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,18 +10,25 @@ import uuid
|
|
10 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
11 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
12 |
|
13 |
-
|
14 |
@st.cache_resource
|
15 |
def load_model():
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
19 |
-
model_id,
|
|
|
|
|
|
|
20 |
)
|
21 |
model.to(device)
|
22 |
|
|
|
23 |
processor = AutoProcessor.from_pretrained(model_id)
|
24 |
|
|
|
25 |
pipe = pipeline(
|
26 |
"automatic-speech-recognition",
|
27 |
model=model,
|
@@ -29,6 +36,7 @@ def load_model():
|
|
29 |
feature_extractor=processor.feature_extractor,
|
30 |
torch_dtype=torch_dtype,
|
31 |
device=device,
|
|
|
32 |
)
|
33 |
return pipe, processor
|
34 |
|
|
|
10 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
11 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
12 |
|
13 |
+
|
14 |
@st.cache_resource
|
15 |
def load_model():
|
16 |
+
# Use a specific Hindi-optimized Whisper model
|
17 |
+
model_id = "openai/whisper-large-v2" # or consider a multilingual model
|
18 |
+
|
19 |
+
# For Hindi, you might want to specify additional parameters
|
20 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
21 |
+
model_id,
|
22 |
+
torch_dtype=torch_dtype,
|
23 |
+
low_cpu_mem_usage=True,
|
24 |
+
use_safetensors=True,
|
25 |
)
|
26 |
model.to(device)
|
27 |
|
28 |
+
# Use the processor from the same model
|
29 |
processor = AutoProcessor.from_pretrained(model_id)
|
30 |
|
31 |
+
# Create pipeline with language specification
|
32 |
pipe = pipeline(
|
33 |
"automatic-speech-recognition",
|
34 |
model=model,
|
|
|
36 |
feature_extractor=processor.feature_extractor,
|
37 |
torch_dtype=torch_dtype,
|
38 |
device=device,
|
39 |
+
generate_kwargs={"language": "hi"} # Specify Hindi language
|
40 |
)
|
41 |
return pipe, processor
|
42 |
|