share true
Browse files
app.py
CHANGED
|
@@ -4,19 +4,19 @@ import torch
|
|
| 4 |
from transformers import pipeline
|
| 5 |
import spaces
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
@spaces.GPU
|
| 8 |
def transcribe_and_respond(audio_file):
|
| 9 |
try:
|
| 10 |
# Load audio
|
| 11 |
audio, sr = librosa.load(audio_file, sr=16000)
|
| 12 |
|
| 13 |
-
# Load Shuka model via pipeline
|
| 14 |
-
pipe = pipeline(
|
| 15 |
-
model="sarvamai/shuka_v1",
|
| 16 |
-
trust_remote_code=True,
|
| 17 |
-
device=0 if torch.cuda.is_available() else -1
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
# Use Shuka's expected format
|
| 21 |
output = pipe({
|
| 22 |
"audio": audio,
|
|
|
|
| 4 |
from transformers import pipeline
|
| 5 |
import spaces
|
| 6 |
|
| 7 |
+
# Initialize model once at startup
|
| 8 |
+
pipe = pipeline(
|
| 9 |
+
model="sarvamai/shuka_v1",
|
| 10 |
+
trust_remote_code=True,
|
| 11 |
+
device=0 if torch.cuda.is_available() else -1
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
@spaces.GPU
|
| 15 |
def transcribe_and_respond(audio_file):
|
| 16 |
try:
|
| 17 |
# Load audio
|
| 18 |
audio, sr = librosa.load(audio_file, sr=16000)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Use Shuka's expected format
|
| 21 |
output = pipe({
|
| 22 |
"audio": audio,
|