sultan-hassan commited on
Commit
5ee5639
·
verified ·
1 Parent(s): af6b5a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -1
app.py CHANGED
@@ -91,6 +91,53 @@ def transcribe_audio(audio_file):
91
  except Exception as e:
92
  return f"Error transcribing audio: {e}"
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  def run_tutor(audio_file):
95
  """Main function to run the tutor."""
96
  question = generate_question(difficulty)
@@ -109,6 +156,10 @@ def run_tutor(audio_file):
109
  yield None, None, feedback_audio, feedback
110
  #return question_audio, feedback_audio, question, user_answer, feedback
111
 
 
 
 
 
112
  # --- Gradio Interface ---
113
  with gr.Blocks() as demo:
114
  gr.Markdown("# Adaptive Language Tutor (Arabic)")
@@ -150,4 +201,5 @@ with gr.Blocks() as demo:
150
  # outputs=[question_audio_output, feedback_audio_output, question_text_output, answer_text_output, feedback_text_output]
151
  # )
152
 
153
- demo.launch()
 
 
91
  except Exception as e:
92
  return f"Error transcribing audio: {e}"
93
 
94
+
95
+
96
+ def run_tutor():
97
+ """Main function to run the tutor."""
98
+ question = generate_question(difficulty)
99
+ question_audio = text_to_speech(question, voice)
100
+
101
+ return question_audio, question
102
+
103
+ def process_answer(audio_file, question, question_audio):
104
+ """Processes the user's answer and provides feedback."""
105
+ user_answer = transcribe_audio(audio_file)
106
+ feedback = evaluate_answer(question, user_answer)
107
+ feedback_audio = text_to_speech(feedback, voice)
108
+
109
+ return feedback_audio, feedback
110
+
111
+
112
+ # --- Gradio Interface ---
113
+ with gr.Blocks() as demo:
114
+ gr.Markdown("# Adaptive Language Tutor (Spanish)")
115
+ with gr.Row():
116
+ question_audio_output = gr.Audio(label="Question")
117
+ question_text_output = gr.Textbox(label="Question Text")
118
+ with gr.Row():
119
+ feedback_audio_output = gr.Audio(label="Feedback")
120
+ feedback_text_output = gr.Textbox(label="Feedback")
121
+ mic_input = gr.Audio(label="Speak Your Answer")
122
+ generate_button = gr.Button("Generate Question")
123
+
124
+ generate_button.click(
125
+ fn=run_tutor,
126
+ outputs=[question_audio_output, question_text_output]
127
+ )
128
+
129
+ mic_input.change(
130
+ fn=process_answer,
131
+ inputs=[mic_input, question_text_output, question_audio_output],
132
+ outputs=[feedback_audio_output, feedback_text_output]
133
+ )
134
+
135
+ demo.launch()
136
+
137
+
138
+
139
+ '''
140
+
141
  def run_tutor(audio_file):
142
  """Main function to run the tutor."""
143
  question = generate_question(difficulty)
 
156
  yield None, None, feedback_audio, feedback
157
  #return question_audio, feedback_audio, question, user_answer, feedback
158
 
159
+
160
+
161
+
162
+
163
  # --- Gradio Interface ---
164
  with gr.Blocks() as demo:
165
  gr.Markdown("# Adaptive Language Tutor (Arabic)")
 
201
  # outputs=[question_audio_output, feedback_audio_output, question_text_output, answer_text_output, feedback_text_output]
202
  # )
203
 
204
+ demo.launch()
205
+ '''