Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,11 +14,16 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
14 |
|
15 |
# load model and processor
|
16 |
model_id = "rbcurzon/whisper-small-fil"
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
model = load_silero_vad()
|
|
|
22 |
client = genai.Client(api_key=os.environ.get("GENAI_API_KEY")) # Do not share api key
|
23 |
|
24 |
"""**FastAPI**"""
|
@@ -58,11 +63,17 @@ async def test(
|
|
58 |
sampling_rate=16000
|
59 |
)
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
result = pipe(
|
62 |
"only_speech.wav", # Transcribe audio
|
63 |
batch_size=8,
|
64 |
return_timestamps=True,
|
65 |
-
generate_kwargs=
|
66 |
)
|
67 |
print(result)
|
68 |
|
@@ -103,4 +114,11 @@ async def test(text: str,
|
|
103 |
result = translate(text, srcLang, tgtLang)
|
104 |
print('Raw: ', text)
|
105 |
print('Translated: ', result)
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# load model and processor
|
16 |
model_id = "rbcurzon/whisper-small-fil"
|
17 |
+
|
18 |
+
pipe = pipeline(
|
19 |
+
"automatic-speech-recognition",
|
20 |
+
model=model_id,
|
21 |
+
chunk_length_s=30,
|
22 |
+
device=device
|
23 |
+
)
|
24 |
+
|
25 |
model = load_silero_vad()
|
26 |
+
|
27 |
client = genai.Client(api_key=os.environ.get("GENAI_API_KEY")) # Do not share api key
|
28 |
|
29 |
"""**FastAPI**"""
|
|
|
63 |
sampling_rate=16000
|
64 |
)
|
65 |
|
66 |
+
generate_kwargs = {
|
67 |
+
"language": "tagalog",
|
68 |
+
"return_timestamps": True,
|
69 |
+
"condition_on_prev_tokens": False,
|
70 |
+
}
|
71 |
+
|
72 |
result = pipe(
|
73 |
"only_speech.wav", # Transcribe audio
|
74 |
batch_size=8,
|
75 |
return_timestamps=True,
|
76 |
+
generate_kwargs=generate_kwargs
|
77 |
)
|
78 |
print(result)
|
79 |
|
|
|
114 |
result = translate(text, srcLang, tgtLang)
|
115 |
print('Raw: ', text)
|
116 |
print('Translated: ', result)
|
117 |
+
|
118 |
+
result_dict = {
|
119 |
+
"text": text,
|
120 |
+
"translated_text": result,
|
121 |
+
"srcLang": srcLang,
|
122 |
+
"tgtLang": tgtLang
|
123 |
+
}
|
124 |
+
return result_dict
|