Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,10 @@ repo_name = "HugoZeballos/rapa_nui_asr_2" # Ajusta al nombre de tu modelo en Hu
|
|
| 19 |
processor = Speech2TextProcessor.from_pretrained(repo_name)
|
| 20 |
model = Speech2TextForConditionalGeneration.from_pretrained(repo_name).to(device)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def transcribe(audio_path):
|
| 23 |
audio, sr = librosa.load(audio_path, sr=16000)
|
| 24 |
inputs = processor(audio, sampling_rate=sr, return_tensors="pt", padding="longest").to("cuda")
|
|
@@ -27,13 +31,15 @@ def transcribe(audio_path):
|
|
| 27 |
predicted_ids = model.generate(inputs["input_features"], attention_mask=inputs["attention_mask"])
|
| 28 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
| 29 |
return transcription
|
| 30 |
-
|
| 31 |
-
# Crear interfaz
|
| 32 |
interface = gr.Interface(
|
| 33 |
-
fn=
|
| 34 |
-
inputs=
|
| 35 |
-
outputs=
|
| 36 |
-
title="
|
| 37 |
)
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
| 19 |
processor = Speech2TextProcessor.from_pretrained(repo_name)
|
| 20 |
model = Speech2TextForConditionalGeneration.from_pretrained(repo_name).to(device)
|
| 21 |
|
| 22 |
+
# Cambiar `source` a una configuraci贸n v谩lida o eliminarlo
|
| 23 |
+
inputs = gr.Audio(type="filepath")
|
| 24 |
+
outputs = gr.Textbox(label="Transcripci贸n")
|
| 25 |
+
|
| 26 |
def transcribe(audio_path):
|
| 27 |
audio, sr = librosa.load(audio_path, sr=16000)
|
| 28 |
inputs = processor(audio, sampling_rate=sr, return_tensors="pt", padding="longest").to("cuda")
|
|
|
|
| 31 |
predicted_ids = model.generate(inputs["input_features"], attention_mask=inputs["attention_mask"])
|
| 32 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
| 33 |
return transcription
|
| 34 |
+
|
| 35 |
+
# Crear interfaz
|
| 36 |
interface = gr.Interface(
|
| 37 |
+
fn=transcribe_audio,
|
| 38 |
+
inputs=inputs,
|
| 39 |
+
outputs=outputs,
|
| 40 |
+
title="ASR Demo"
|
| 41 |
)
|
| 42 |
|
| 43 |
+
# Ejecutar la app
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
interface.launch()
|