gerasdf
commited on
Commit
·
ae6af5e
1
Parent(s):
db7f523
auth required also for audio input (uses model credits)
Browse files
query.py
CHANGED
@@ -143,19 +143,23 @@ def chat(message, history, state):
|
|
143 |
else:
|
144 |
yield f"{time.ctime()}: You said: {message}"
|
145 |
|
146 |
-
def on_audio(path):
|
147 |
-
if not
|
148 |
-
|
149 |
-
|
150 |
-
text = oai_client.audio.transcriptions.create(
|
151 |
-
model="whisper-1",
|
152 |
-
file=open(path, "rb"),
|
153 |
-
response_format="text"
|
154 |
-
)
|
155 |
else:
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
-
|
159 |
|
160 |
def gr_main():
|
161 |
theme = gr.Theme.from_hub("freddyaboulton/[email protected]")
|
@@ -200,7 +204,7 @@ def gr_main():
|
|
200 |
|
201 |
waveform_options=gr.WaveformOptions(sample_rate=16000))
|
202 |
mic.change(
|
203 |
-
on_audio, [mic], [iface.textbox, mic]
|
204 |
).then(
|
205 |
lambda x:None,
|
206 |
js='function (text){debugger; if (text) document.getElementById("submit_btn").click(); return [text]}',
|
|
|
143 |
else:
|
144 |
yield f"{time.ctime()}: You said: {message}"
|
145 |
|
146 |
+
def on_audio(path, state):
|
147 |
+
if (state is None) or (not state['user']):
|
148 |
+
gr.Warning("You need to authenticate first")
|
149 |
+
return (gr.update(), None)
|
|
|
|
|
|
|
|
|
|
|
150 |
else:
|
151 |
+
if not path:
|
152 |
+
return [gr.update(), None]
|
153 |
+
if AI:
|
154 |
+
text = oai_client.audio.transcriptions.create(
|
155 |
+
model="whisper-1",
|
156 |
+
file=open(path, "rb"),
|
157 |
+
response_format="text"
|
158 |
+
)
|
159 |
+
else:
|
160 |
+
text = f"{time.ctime()}: You said something"
|
161 |
|
162 |
+
return (text, None)
|
163 |
|
164 |
def gr_main():
|
165 |
theme = gr.Theme.from_hub("freddyaboulton/[email protected]")
|
|
|
204 |
|
205 |
waveform_options=gr.WaveformOptions(sample_rate=16000))
|
206 |
mic.change(
|
207 |
+
on_audio, [mic, state], [iface.textbox, mic]
|
208 |
).then(
|
209 |
lambda x:None,
|
210 |
js='function (text){debugger; if (text) document.getElementById("submit_btn").click(); return [text]}',
|