Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,8 +48,14 @@ else:
|
|
| 48 |
rtc_configuration = None
|
| 49 |
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
@spaces.GPU
|
| 52 |
-
def
|
| 53 |
segment = AudioSegment(audio[1].tobytes(), frame_rate=audio[0], sample_width=audio[1].dtype.itemsize, channels=1)
|
| 54 |
|
| 55 |
name = str(uuid.uuid4()) + ".mp3"
|
|
@@ -73,11 +79,10 @@ def transcribe(audio: tuple[int, np.ndarray], transformers_convo: list[dict], gr
|
|
| 73 |
generate_ids = model.generate(**inputs, max_length=256)
|
| 74 |
generate_ids = generate_ids[:, inputs["input_ids"].size(1):]
|
| 75 |
response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 76 |
-
print("response", response)
|
| 77 |
transformers_convo.append({"role": "assistant", "content": response})
|
| 78 |
gradio_convo.append({"role": "assistant", "content": response})
|
| 79 |
|
| 80 |
-
yield
|
| 81 |
|
| 82 |
|
| 83 |
with gr.Blocks() as demo:
|
|
@@ -93,8 +98,8 @@ with gr.Blocks() as demo:
|
|
| 93 |
with gr.Column():
|
| 94 |
transcript = gr.Chatbot(label="transcript", type="messages")
|
| 95 |
|
| 96 |
-
audio.stream(ReplyOnPause(
|
| 97 |
-
audio.on_additional_outputs(
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
demo.launch()
|
|
|
|
| 48 |
rtc_configuration = None
|
| 49 |
|
| 50 |
|
| 51 |
+
|
| 52 |
+
def yield_audio(audio: tuple[int, np.ndarray]):
|
| 53 |
+
yield AdditionalOutputs(audio)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
@spaces.GPU
|
| 58 |
+
def respond(transformers_convo: list[dict], gradio_convo: list[dict], audio: tuple[int, np.ndarray], ):
|
| 59 |
segment = AudioSegment(audio[1].tobytes(), frame_rate=audio[0], sample_width=audio[1].dtype.itemsize, channels=1)
|
| 60 |
|
| 61 |
name = str(uuid.uuid4()) + ".mp3"
|
|
|
|
| 79 |
generate_ids = model.generate(**inputs, max_length=256)
|
| 80 |
generate_ids = generate_ids[:, inputs["input_ids"].size(1):]
|
| 81 |
response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
|
|
|
| 82 |
transformers_convo.append({"role": "assistant", "content": response})
|
| 83 |
gradio_convo.append({"role": "assistant", "content": response})
|
| 84 |
|
| 85 |
+
yield transformers_convo, gradio_convo
|
| 86 |
|
| 87 |
|
| 88 |
with gr.Blocks() as demo:
|
|
|
|
| 98 |
with gr.Column():
|
| 99 |
transcript = gr.Chatbot(label="transcript", type="messages")
|
| 100 |
|
| 101 |
+
audio.stream(ReplyOnPause(yield_audio), inputs=[audio], outputs=[audio])
|
| 102 |
+
audio.on_additional_outputs(respond, outputs=[transformers_convo, transcript])
|
| 103 |
|
| 104 |
if __name__ == "__main__":
|
| 105 |
demo.launch()
|