DurreSudoku commited on
Commit
d5e5cc3
·
verified ·
1 Parent(s): 1ff72eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -8,7 +8,7 @@ import logging
8
 
9
  all_images = os.listdir("assets")
10
  current_image = None
11
- pipe = pipeline(task="automatic-speech-recognition", model="DurreSudoku/whisper-small-sv", processor="openai/whisper-small") # change to "your-username/the-name-you-picked"
12
 
13
  def test_func():
14
  random_int = random.randint(1, 100)
@@ -55,12 +55,15 @@ def transcribe(audio_input):
55
  transcribed_audio = transcribed_audio.replace("?", "")
56
  transcribed_audio = transcribed_audio.lower()
57
 
58
- text_list = transcribed_audio.split(" ")
59
 
60
  correct_answer = current_image.split(".png")[0]
 
 
61
 
62
- # Check for a perfect match.
63
- if correct_answer in text_list:
 
64
  return f"Correct! The answer is {correct_answer}."
65
 
66
  # Check for partial match, in case the model mistakes a letter or two.
@@ -86,7 +89,7 @@ with gr.Blocks(title="Interactive Language Learning") as demo:
86
  """)
87
  with gr.Row():
88
  with gr.Column():
89
- audio = gr.Audio(sources="microphone", type="numpy", label="Record your answer here")
90
  with gr.Column():
91
  image = gr.Image(value=open_image(),type="pil", interactive=False)
92
  with gr.Row():
 
8
 
9
  all_images = os.listdir("assets")
10
  current_image = None
11
+ pipe = pipeline(task="automatic-speech-recognition", model="DurreSudoku/whisper-small-sv") # change to "your-username/the-name-you-picked"
12
 
13
  def test_func():
14
  random_int = random.randint(1, 100)
 
55
  transcribed_audio = transcribed_audio.replace("?", "")
56
  transcribed_audio = transcribed_audio.lower()
57
 
58
+
59
 
60
  correct_answer = current_image.split(".png")[0]
61
+ text_list = transcribed_audio.split(" ")
62
+ ratio = SequenceMatcher(None, transcribed_audio, correct_answer).ratio()
63
 
64
+ if ratio >= 0.75:
65
+ return f"Correct! The answer is {correct_answer}."
66
+ elif correct_answer in text_list:
67
  return f"Correct! The answer is {correct_answer}."
68
 
69
  # Check for partial match, in case the model mistakes a letter or two.
 
89
  """)
90
  with gr.Row():
91
  with gr.Column():
92
+ audio = gr.Audio(sources="microphone", type="filepath", label="Record your answer here")
93
  with gr.Column():
94
  image = gr.Image(value=open_image(),type="pil", interactive=False)
95
  with gr.Row():