Update app.py
Browse files
app.py
CHANGED
|
@@ -35,6 +35,8 @@ ORIGINAL:
|
|
| 35 |
|
| 36 |
TRANSCRIPT:
|
| 37 |
{transcribed_text}
|
|
|
|
|
|
|
| 38 |
"""
|
| 39 |
|
| 40 |
PROMPT_TEMPLATE_2 = """\
|
|
@@ -68,13 +70,12 @@ then return the revised script.
|
|
| 68 |
# ----------------------------
|
| 69 |
# Helpers: STT & LLM calls
|
| 70 |
# ----------------------------
|
| 71 |
-
def transcribe_audio(
|
| 72 |
"""
|
| 73 |
Prioritize uploaded file if both provided.
|
| 74 |
Returns the transcribed text (or an error message).
|
| 75 |
"""
|
| 76 |
-
|
| 77 |
-
audio_path = upload_path or record_path
|
| 78 |
if not audio_path:
|
| 79 |
return "No audio provided. Please upload or record audio."
|
| 80 |
|
|
@@ -140,11 +141,11 @@ def call_llm_302(prompt: str) -> str:
|
|
| 140 |
# ----------------------------
|
| 141 |
# Button handlers
|
| 142 |
# ----------------------------
|
| 143 |
-
def on_click_transcribe(
|
| 144 |
"""
|
| 145 |
Button 1: Transcribe audio -> fill Textbox1 (transcribed text, non-editable).
|
| 146 |
"""
|
| 147 |
-
text = transcribe_audio(
|
| 148 |
return gr.update(value=text)
|
| 149 |
|
| 150 |
|
|
@@ -187,8 +188,8 @@ with gr.Blocks(title="DeStammerer: Script Revise (Minimal)") as demo:
|
|
| 187 |
|
| 188 |
# Row 1: [audio upload, audio record, button1]
|
| 189 |
with gr.Row():
|
| 190 |
-
audio_upload = gr.Audio(label="Upload Audio", sources=["upload"], type="filepath")
|
| 191 |
audio_record = gr.Audio(label="Record Audio", sources=["microphone"], type="filepath")
|
|
|
|
| 192 |
btn_transcribe = gr.Button("1) Transcribe")
|
| 193 |
|
| 194 |
# Row 2: [textbox1 (ASR, readonly), textbox2 (original input), button2]
|
|
@@ -205,9 +206,12 @@ with gr.Blocks(title="DeStammerer: Script Revise (Minimal)") as demo:
|
|
| 205 |
btn_rewrite = gr.Button("3) Revise Script")
|
| 206 |
|
| 207 |
# Wiring
|
|
|
|
|
|
|
|
|
|
| 208 |
btn_transcribe.click(
|
| 209 |
fn=on_click_transcribe,
|
| 210 |
-
inputs=[
|
| 211 |
outputs=[txt_transcribed],
|
| 212 |
)
|
| 213 |
|
|
|
|
| 35 |
|
| 36 |
TRANSCRIPT:
|
| 37 |
{transcribed_text}
|
| 38 |
+
|
| 39 |
+
Never give any suggestion. Only return a concise, principled diagnosis notes with easy-to-stutter scenarios.
|
| 40 |
"""
|
| 41 |
|
| 42 |
PROMPT_TEMPLATE_2 = """\
|
|
|
|
| 70 |
# ----------------------------
|
| 71 |
# Helpers: STT & LLM calls
|
| 72 |
# ----------------------------
|
| 73 |
+
def transcribe_audio(record_path: str | None) -> str:
|
| 74 |
"""
|
| 75 |
Prioritize uploaded file if both provided.
|
| 76 |
Returns the transcribed text (or an error message).
|
| 77 |
"""
|
| 78 |
+
audio_path = record_path
|
|
|
|
| 79 |
if not audio_path:
|
| 80 |
return "No audio provided. Please upload or record audio."
|
| 81 |
|
|
|
|
| 141 |
# ----------------------------
|
| 142 |
# Button handlers
|
| 143 |
# ----------------------------
|
| 144 |
+
def on_click_transcribe(record_path):
|
| 145 |
"""
|
| 146 |
Button 1: Transcribe audio -> fill Textbox1 (transcribed text, non-editable).
|
| 147 |
"""
|
| 148 |
+
text = transcribe_audio(record_path)
|
| 149 |
return gr.update(value=text)
|
| 150 |
|
| 151 |
|
|
|
|
| 188 |
|
| 189 |
# Row 1: [audio upload, audio record, button1]
|
| 190 |
with gr.Row():
|
|
|
|
| 191 |
audio_record = gr.Audio(label="Record Audio", sources=["microphone"], type="filepath")
|
| 192 |
+
audio_download = gr.File(label="Audio Download", interactive=False)
|
| 193 |
btn_transcribe = gr.Button("1) Transcribe")
|
| 194 |
|
| 195 |
# Row 2: [textbox1 (ASR, readonly), textbox2 (original input), button2]
|
|
|
|
| 206 |
btn_rewrite = gr.Button("3) Revise Script")
|
| 207 |
|
| 208 |
# Wiring
|
| 209 |
+
passthrough = lambda audio_path: audio_path
|
| 210 |
+
audio_record.change(fn=passthrough, inputs=audio_record, outputs=audio_download)
|
| 211 |
+
|
| 212 |
btn_transcribe.click(
|
| 213 |
fn=on_click_transcribe,
|
| 214 |
+
inputs=[audio_record],
|
| 215 |
outputs=[txt_transcribed],
|
| 216 |
)
|
| 217 |
|