Spaces:
Runtime error
Runtime error
Commit
·
f607038
1
Parent(s):
60b210b
feat: fix bugs
Browse files- app.py +40 -4
- requirements.txt +4 -0
app.py
CHANGED
@@ -1,10 +1,46 @@
|
|
1 |
-
import gradio as gr
|
2 |
import os
|
3 |
|
|
|
|
|
|
|
|
|
|
|
4 |
hf_token = os.getenv("hf_token")
|
5 |
|
6 |
if hf_token is None:
|
7 |
-
raise ValueError(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
gr.load("models/avalonai/whisper-small-jv", hf_token=hf_token).launch()
|
|
|
|
|
1 |
import os
|
2 |
|
3 |
+
import gradio as gr
|
4 |
+
import librosa
|
5 |
+
import torch
|
6 |
+
from transformers import WhisperForConditionalGeneration, WhisperProcessor
|
7 |
+
|
8 |
hf_token = os.getenv("hf_token")
|
9 |
|
10 |
if hf_token is None:
|
11 |
+
raise ValueError(
|
12 |
+
"Hugging Face token not found. Please set the 'hf_token' environment variable."
|
13 |
+
)
|
14 |
+
|
15 |
+
processor = WhisperProcessor.from_pretrained(
|
16 |
+
"openai/whisper-small",
|
17 |
+
language="Indonesian",
|
18 |
+
task="transcribe",
|
19 |
+
use_auth_token=hf_token,
|
20 |
+
)
|
21 |
+
model = WhisperForConditionalGeneration.from_pretrained(
|
22 |
+
"avalonai/whisper-small-jv", use_auth_token=hf_token
|
23 |
+
)
|
24 |
+
|
25 |
+
|
26 |
+
def transcribe(audio):
|
27 |
+
audio, sampling_rate = librosa.load(audio, sr=16000)
|
28 |
+
audio_input = processor(audio, return_tensors="pt", sampling_rate=16000)
|
29 |
+
input_values = audio_input.input_features
|
30 |
+
|
31 |
+
with torch.no_grad():
|
32 |
+
generated_ids = model.generate(input_values)
|
33 |
+
|
34 |
+
transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
35 |
+
return transcription[0]
|
36 |
+
|
37 |
+
|
38 |
+
iface = gr.Interface(
|
39 |
+
fn=transcribe,
|
40 |
+
inputs=gr.Audio(sources="microphone", type="filepath"),
|
41 |
+
outputs="text",
|
42 |
+
title="Speech-to-text on Javanese Language Demo",
|
43 |
+
description="Ini adalah platform untuk pengujian model speech-to-text pada bahasa Jawa oleh Avalon AI. Silahkan coba dengan mengucapkan kalimat",
|
44 |
+
)
|
45 |
|
46 |
+
iface.launch()
|
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.28.3
|
2 |
+
librosa==0.10.1
|
3 |
+
torch==2.2.1
|
4 |
+
transformers==4.35.2
|