Update spoken_module.py
Browse files- spoken_module.py +40 -7
spoken_module.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
import uuid
|
| 4 |
from gtts import gTTS
|
|
@@ -15,13 +14,30 @@ def spoken_dashboard():
|
|
| 15 |
<div id="header" style="text-align: center;">
|
| 16 |
<img src="file/images/chatter_owl.png" width="120">
|
| 17 |
<h2>π¦ Meet <strong>Chatter the Owl</strong></h2>
|
| 18 |
-
<p>Enter your name, choose a language, and speak! Iβll help you grow as a communicator.</p>
|
| 19 |
</div>
|
| 20 |
""")
|
| 21 |
|
| 22 |
nickname_box = gr.Textbox(label="π€ Your Nickname", placeholder="Enter your name...")
|
| 23 |
language_dropdown = gr.Dropdown(label="π Select Your Language", choices=list(LANG_CODES.keys()), value="English")
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
with gr.Row():
|
| 26 |
audio_input = gr.Audio(type="filepath", label="π Speak or Upload Audio")
|
| 27 |
|
|
@@ -37,20 +53,36 @@ def spoken_dashboard():
|
|
| 37 |
example_box = gr.Textbox(label="π£ Suggested Improvement", visible=True, placeholder="Click to generate improved speech...")
|
| 38 |
history_table = gr.Dataframe(headers=["π Timestamp", "π Language", "π Transcript (Preview)", "π Feedback (Preview)"])
|
| 39 |
|
| 40 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
if not audio_file:
|
| 42 |
return "", "No audio received.", None, "", []
|
| 43 |
|
| 44 |
wav_path = convert_to_wav(audio_file)
|
| 45 |
transcript = transcribe_audio(wav_path)
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
lang_code = LANG_CODES.get(language, "en")
|
| 49 |
tts = gTTS(feedback_text, lang=lang_code)
|
| 50 |
mp3_path = f"/tmp/{uuid.uuid4()}.mp3"
|
| 51 |
tts.save(mp3_path)
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
sessions = fetch_user_sessions(nickname)
|
| 55 |
session_table = [[s.timestamp, s.language, s.transcript[:40], s.feedback[:40]] for s in sessions]
|
| 56 |
|
|
@@ -58,8 +90,9 @@ def spoken_dashboard():
|
|
| 58 |
|
| 59 |
audio_input.change(
|
| 60 |
fn=tutor_feedback,
|
| 61 |
-
inputs=[audio_input, language_dropdown, nickname_box],
|
| 62 |
-
outputs=[transcript_box, feedback_box, audio_output, hidden_transcript, history_table]
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
try_again.click(fn=lambda: ("", "", None, "", "", []),
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import uuid
|
| 3 |
from gtts import gTTS
|
|
|
|
| 14 |
<div id="header" style="text-align: center;">
|
| 15 |
<img src="file/images/chatter_owl.png" width="120">
|
| 16 |
<h2>π¦ Meet <strong>Chatter the Owl</strong></h2>
|
| 17 |
+
<p>Enter your name, choose a language and goal, and speak! Iβll help you grow as a communicator.</p>
|
| 18 |
</div>
|
| 19 |
""")
|
| 20 |
|
| 21 |
nickname_box = gr.Textbox(label="π€ Your Nickname", placeholder="Enter your name...")
|
| 22 |
language_dropdown = gr.Dropdown(label="π Select Your Language", choices=list(LANG_CODES.keys()), value="English")
|
| 23 |
|
| 24 |
+
goal_dropdown = gr.Dropdown(
|
| 25 |
+
label="π― Communication Goal",
|
| 26 |
+
choices=[
|
| 27 |
+
"Interview preparation",
|
| 28 |
+
"Public speaking",
|
| 29 |
+
"Class presentation",
|
| 30 |
+
"General improvement"
|
| 31 |
+
],
|
| 32 |
+
value="General improvement"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
focus_checkboxes = gr.CheckboxGroup(
|
| 36 |
+
label="π§ Areas to Focus On",
|
| 37 |
+
choices=["Clarity", "Structure", "Fluency", "Tone", "Content Relevance"],
|
| 38 |
+
value=["Clarity", "Structure", "Fluency", "Tone", "Content Relevance"]
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
with gr.Row():
|
| 42 |
audio_input = gr.Audio(type="filepath", label="π Speak or Upload Audio")
|
| 43 |
|
|
|
|
| 53 |
example_box = gr.Textbox(label="π£ Suggested Improvement", visible=True, placeholder="Click to generate improved speech...")
|
| 54 |
history_table = gr.Dataframe(headers=["π Timestamp", "π Language", "π Transcript (Preview)", "π Feedback (Preview)"])
|
| 55 |
|
| 56 |
+
def fetch_last_transcript(nickname):
|
| 57 |
+
if not nickname:
|
| 58 |
+
return None
|
| 59 |
+
sessions = fetch_user_sessions(nickname)
|
| 60 |
+
return sessions[-1].transcript if sessions else None
|
| 61 |
+
|
| 62 |
+
def tutor_feedback(audio_file, language, nickname, goal, focus_areas):
|
| 63 |
if not audio_file:
|
| 64 |
return "", "No audio received.", None, "", []
|
| 65 |
|
| 66 |
wav_path = convert_to_wav(audio_file)
|
| 67 |
transcript = transcribe_audio(wav_path)
|
| 68 |
+
previous = fetch_last_transcript(nickname)
|
| 69 |
+
|
| 70 |
+
feedback_text = generate_feedback(
|
| 71 |
+
transcript=transcript,
|
| 72 |
+
language=language,
|
| 73 |
+
goal=goal,
|
| 74 |
+
focus_areas=focus_areas,
|
| 75 |
+
previous_transcript=previous
|
| 76 |
+
)
|
| 77 |
|
| 78 |
lang_code = LANG_CODES.get(language, "en")
|
| 79 |
tts = gTTS(feedback_text, lang=lang_code)
|
| 80 |
mp3_path = f"/tmp/{uuid.uuid4()}.mp3"
|
| 81 |
tts.save(mp3_path)
|
| 82 |
|
| 83 |
+
if nickname:
|
| 84 |
+
save_to_db(nickname, transcript, feedback_text, language)
|
| 85 |
+
|
| 86 |
sessions = fetch_user_sessions(nickname)
|
| 87 |
session_table = [[s.timestamp, s.language, s.transcript[:40], s.feedback[:40]] for s in sessions]
|
| 88 |
|
|
|
|
| 90 |
|
| 91 |
audio_input.change(
|
| 92 |
fn=tutor_feedback,
|
| 93 |
+
inputs=[audio_input, language_dropdown, nickname_box, goal_dropdown, focus_checkboxes],
|
| 94 |
+
outputs=[transcript_box, feedback_box, audio_output, hidden_transcript, history_table],
|
| 95 |
+
show_progress="minimal"
|
| 96 |
)
|
| 97 |
|
| 98 |
try_again.click(fn=lambda: ("", "", None, "", "", []),
|