sultan-hassan commited on
Commit
4d7e5af
·
verified ·
1 Parent(s): bb9dd5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -56,7 +56,7 @@ def evaluate_answer(question, answer):
56
 
57
  def text_to_speech(text, voice):
58
  """Converts text to speech using ElevenLabs."""
59
- audio = elevenlabs.generate(text=text, voice=voice, model="eleven_monolingual_v1")
60
  return audio
61
 
62
  def transcribe_audio(audio_file):
@@ -76,7 +76,7 @@ def run_tutor(audio_file):
76
  question_audio = text_to_speech(question, voice)
77
 
78
  # Display the question in the interface
79
- yield question_audio, None, question, None, None # Send the question audio and text
80
 
81
  # Transcribe the user's answer
82
  user_answer = transcribe_audio(audio_file)
@@ -85,7 +85,7 @@ def run_tutor(audio_file):
85
  feedback = evaluate_answer(question, user_answer)
86
  feedback_audio = text_to_speech(feedback, voice)
87
 
88
- yield None, feedback_audio, question, user_answer, feedback # Send the feedback audio and text
89
  #return question_audio, feedback_audio, question, user_answer, feedback
90
 
91
  # --- Gradio Interface ---
@@ -95,15 +95,28 @@ with gr.Blocks() as demo:
95
  question_audio_output = gr.Audio(label="Question")
96
  feedback_audio_output = gr.Audio(label="Feedback")
97
  with gr.Row():
98
- question_text_output = gr.Textbox(label="Question Text")
99
- answer_text_output = gr.Textbox(label="Your Answer")
100
  feedback_text_output = gr.Textbox(label="Feedback")
101
  mic_input = gr.Audio(label="Speak Your Answer")
 
102
 
103
- mic_input.change(
104
  fn=run_tutor,
105
  inputs=mic_input,
106
- outputs=[question_audio_output, feedback_audio_output, question_text_output, answer_text_output, feedback_text_output]
107
  )
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  demo.launch()
 
56
 
57
  def text_to_speech(text, voice):
58
  """Converts text to speech using ElevenLabs."""
59
+ audio = elevenlabs.tts(text=text, voice=voice, model="eleven_monolingual_v1")
60
  return audio
61
 
62
  def transcribe_audio(audio_file):
 
76
  question_audio = text_to_speech(question, voice)
77
 
78
  # Display the question in the interface
79
+ yield question_audio, question, None, None
80
 
81
  # Transcribe the user's answer
82
  user_answer = transcribe_audio(audio_file)
 
85
  feedback = evaluate_answer(question, user_answer)
86
  feedback_audio = text_to_speech(feedback, voice)
87
 
88
+ yield None, None, feedback_audio, feedback
89
  #return question_audio, feedback_audio, question, user_answer, feedback
90
 
91
  # --- Gradio Interface ---
 
95
  question_audio_output = gr.Audio(label="Question")
96
  feedback_audio_output = gr.Audio(label="Feedback")
97
  with gr.Row():
98
+ feedback_audio_output = gr.Audio(label="Feedback")
 
99
  feedback_text_output = gr.Textbox(label="Feedback")
100
  mic_input = gr.Audio(label="Speak Your Answer")
101
+ generate_button = gr.Button("Generate Question")
102
 
103
+ generate_button.click(
104
  fn=run_tutor,
105
  inputs=mic_input,
106
+ outputs=[question_audio_output, question_text_output, feedback_audio_output, feedback_text_output]
107
  )
108
 
109
+
110
+ #
111
+ # question_text_output = gr.Textbox(label="Question Text")
112
+ # answer_text_output = gr.Textbox(label="Your Answer")
113
+ # feedback_text_output = gr.Textbox(label="Feedback")
114
+ # mic_input = gr.Audio(label="Speak Your Answer")#
115
+
116
+ # mic_input.change(
117
+ # fn=run_tutor,
118
+ # inputs=mic_input,
119
+ # outputs=[question_audio_output, feedback_audio_output, question_text_output, answer_text_output, feedback_text_output]
120
+ # )
121
+
122
  demo.launch()