Update app.py
Browse files
app.py
CHANGED
|
@@ -43,9 +43,21 @@ The model was trained on Thai audio recordings with the following sentences: \n
|
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
-
def predict(
|
| 47 |
max_length = 100000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
model.eval()
|
| 50 |
with torch.no_grad():
|
| 51 |
wav_data, _ = sf.read(file_path.name)
|
|
@@ -64,9 +76,13 @@ def predict(file_path):
|
|
| 64 |
predicted_class_id = torch.argmax(logits, dim=-1).item()
|
| 65 |
|
| 66 |
return predicted_class_id
|
|
|
|
| 67 |
gr.Interface(
|
| 68 |
fn=predict,
|
| 69 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
| 70 |
outputs="text",
|
| 71 |
title=title,
|
| 72 |
description=description,
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
+
def predict(file_upload,microphone_path):
|
| 47 |
max_length = 100000
|
| 48 |
+
file_path = file_upload
|
| 49 |
+
if (microphone is not None) and (file_upload is not None):
|
| 50 |
+
warn_output = (
|
| 51 |
+
"WARNING: You've uploaded an audio file and used the microphone. "
|
| 52 |
+
"The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
| 53 |
+
)
|
| 54 |
|
| 55 |
+
elif (microphone is None) and (file_upload is None):
|
| 56 |
+
return "ERROR: You have to either use the microphone or upload an audio file"
|
| 57 |
+
if(microphone is not None):
|
| 58 |
+
file_path = microphone
|
| 59 |
+
if(file_upload is not None):
|
| 60 |
+
file_path = file_upload
|
| 61 |
model.eval()
|
| 62 |
with torch.no_grad():
|
| 63 |
wav_data, _ = sf.read(file_path.name)
|
|
|
|
| 76 |
predicted_class_id = torch.argmax(logits, dim=-1).item()
|
| 77 |
|
| 78 |
return predicted_class_id
|
| 79 |
+
|
| 80 |
gr.Interface(
|
| 81 |
fn=predict,
|
| 82 |
+
inputs=[
|
| 83 |
+
gr.inputs.Audio(source="upload", type="filepath", optional=True),
|
| 84 |
+
gr.inputs.Audio(source="microphone", type="filepath", optional=True),
|
| 85 |
+
],
|
| 86 |
outputs="text",
|
| 87 |
title=title,
|
| 88 |
description=description,
|