Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import soundfile as sf
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# from s2s import generate
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def get_tmp_path(file_name: str):
|
| 9 |
+
temp_dir = "tempor"
|
| 10 |
+
if not os.path.exists(temp_dir):
|
| 11 |
+
os.makedirs(temp_dir)
|
| 12 |
+
return os.path.join(temp_dir, file_name)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def process_audio(audio_file):
|
| 16 |
+
# result_audio_arr, sample_rate = generate(audio_file, lambda msg: gr.Info(msg))
|
| 17 |
+
|
| 18 |
+
gr.Info("Writing response")
|
| 19 |
+
target_path = get_tmp_path("processed_audio.wav")
|
| 20 |
+
sf.write(target_path, result_audio_arr, sample_rate)
|
| 21 |
+
|
| 22 |
+
return target_path
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=process_audio,
|
| 27 |
+
inputs=[gr.Audio(label="User Input", type="filepath", format="wav")],
|
| 28 |
+
outputs=[gr.Audio(label="Response")],
|
| 29 |
+
title="Speech to Speech with Mini Omni",
|
| 30 |
+
description='<h2 style="text-align:center;">Ask anything in English and get the audio response!</h2>',
|
| 31 |
+
article="Generation will take a while. Be patient! :)</br>Wait for a few seconds before your recorded audio is fully uploaded.</br>Retry if you encounter any error.",
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|