Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from app.pipeline import run_text, run_voice
|
| 4 |
+
|
| 5 |
+
def ui_text(text):
|
| 6 |
+
# expected: returns dict or tuple; adapt if needed
|
| 7 |
+
result = run_text(text)
|
| 8 |
+
return (
|
| 9 |
+
result["user_text"],
|
| 10 |
+
result["user_normalized"],
|
| 11 |
+
result["assistant_text_raw"],
|
| 12 |
+
result["assistant_text_tts"],
|
| 13 |
+
result["audio_path"],
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
def ui_voice(audio_fp):
|
| 17 |
+
result = run_voice(audio_fp)
|
| 18 |
+
return (
|
| 19 |
+
result["user_text"],
|
| 20 |
+
result["user_normalized"],
|
| 21 |
+
result["assistant_text_raw"],
|
| 22 |
+
result["assistant_text_tts"],
|
| 23 |
+
result["audio_path"],
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
gr.Markdown("Egyptian Arabic Voice Chatbot")
|
| 28 |
+
|
| 29 |
+
with gr.Tab("Text"):
|
| 30 |
+
inp = gr.Textbox(label="Input (Egyptian Arabic)")
|
| 31 |
+
out_user = gr.Textbox(label="User Text")
|
| 32 |
+
out_norm = gr.Textbox(label="Normalized")
|
| 33 |
+
out_raw = gr.Textbox(label="LLM Raw Response")
|
| 34 |
+
out_tts = gr.Textbox(label="TTS-ready Response")
|
| 35 |
+
out_aud = gr.Audio(label="Bot Audio", type="filepath")
|
| 36 |
+
btn = gr.Button("Send")
|
| 37 |
+
btn.click(ui_text, inputs=inp, outputs=[out_user, out_norm, out_raw, out_tts, out_aud])
|
| 38 |
+
|
| 39 |
+
with gr.Tab("Voice"):
|
| 40 |
+
v_in = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Record / Upload")
|
| 41 |
+
v_user = gr.Textbox(label="User Text (ASR)")
|
| 42 |
+
v_norm = gr.Textbox(label="Normalized")
|
| 43 |
+
v_raw = gr.Textbox(label="LLM Raw Response")
|
| 44 |
+
v_tts = gr.Textbox(label="TTS-ready Response")
|
| 45 |
+
v_out = gr.Audio(label="Bot Audio", type="filepath")
|
| 46 |
+
v_btn = gr.Button("Send Voice")
|
| 47 |
+
v_btn.click(ui_voice, inputs=v_in, outputs=[v_user, v_norm, v_raw, v_tts, v_out])
|
| 48 |
+
|
| 49 |
+
demo.queue()
|
| 50 |
+
demo.launch()
|