tiennguyenbnbk
commited on
Commit
•
c4e772c
1
Parent(s):
a93606b
Update app.py
Browse files
app.py
CHANGED
@@ -61,18 +61,23 @@ def download_audio_file(url, filename=None):
|
|
61 |
with open(filename, "wb") as f:
|
62 |
f.write(response.content)
|
63 |
|
|
|
64 |
|
65 |
-
def pa_check(microphone, file_upload, reference_text):
|
66 |
-
if (microphone is not None) and (file_upload is not None):
|
67 |
-
warn_output = (
|
68 |
-
"WARNING: You've uploaded an audio file and used the microphone. "
|
69 |
-
"The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
70 |
-
)
|
71 |
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
|
|
|
|
|
|
|
76 |
|
77 |
result = send_req(reference_text, file)
|
78 |
try:
|
@@ -92,7 +97,7 @@ def pa_check(microphone, file_upload, reference_text):
|
|
92 |
demo = gr.Interface(
|
93 |
fn=pa_check,
|
94 |
inputs=[
|
95 |
-
|
96 |
gr.Audio(sources="microphone", type="filepath"),
|
97 |
gr.Audio(sources="upload", type="filepath"),
|
98 |
gr.Textbox(label="Reference text", type="text", placeholder="How are you?|What is your name?"),
|
@@ -104,9 +109,8 @@ demo = gr.Interface(
|
|
104 |
],
|
105 |
theme="huggingface",
|
106 |
title="Pronunciation Assessment",
|
107 |
-
allow_flagging="never"
|
108 |
)
|
109 |
-
|
110 |
demo.launch(auth=(os.environ['username'], os.environ['password']))
|
111 |
|
112 |
|
|
|
61 |
with open(filename, "wb") as f:
|
62 |
f.write(response.content)
|
63 |
|
64 |
+
return filename
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
+
def pa_check(url_audio, microphone, file_upload, reference_text):
|
68 |
+
if url_audio:
|
69 |
+
file = download_audio_file(url_audio)
|
70 |
+
else:
|
71 |
+
if (microphone is not None) and (file_upload is not None):
|
72 |
+
warn_output = (
|
73 |
+
"WARNING: You've uploaded an audio file and used the microphone. "
|
74 |
+
"The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
75 |
+
)
|
76 |
|
77 |
+
elif (microphone is None) and (file_upload is None):
|
78 |
+
return "ERROR: You have to either use the microphone or upload an audio file"
|
79 |
+
|
80 |
+
file = microphone if microphone is not None else file_upload
|
81 |
|
82 |
result = send_req(reference_text, file)
|
83 |
try:
|
|
|
97 |
demo = gr.Interface(
|
98 |
fn=pa_check,
|
99 |
inputs=[
|
100 |
+
gr.Textbox(label="Url audio", type="text", placeholder="Download audio form url"),
|
101 |
gr.Audio(sources="microphone", type="filepath"),
|
102 |
gr.Audio(sources="upload", type="filepath"),
|
103 |
gr.Textbox(label="Reference text", type="text", placeholder="How are you?|What is your name?"),
|
|
|
109 |
],
|
110 |
theme="huggingface",
|
111 |
title="Pronunciation Assessment",
|
112 |
+
allow_flagging="never"
|
113 |
)
|
|
|
114 |
demo.launch(auth=(os.environ['username'], os.environ['password']))
|
115 |
|
116 |
|