Vadym Myroshnyk commited on
Commit
3b9ff2a
·
1 Parent(s): 2e48cd0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from rapidfuzz import fuzz, process
3
+
4
+
5
+ def highlight_fuzzy_diff(user_text, original_text):
6
+ user_words = user_text.strip().split()
7
+ original_words = original_text.strip().split()
8
+ highlighted = []
9
+
10
+ used_indices = set()
11
+
12
+ for word in user_words:
13
+ match, score, idx = process.extractOne(word, original_words, scorer=fuzz.ratio)
14
+ if score > 85 and idx not in used_indices:
15
+ highlighted.append(
16
+ f"<span style='background-color:#f0f0f0; color:#333; padding:4px 10px; "
17
+ f"margin:4px; border-radius:999px; font-weight:500; display:inline-block;'>{word}</span>"
18
+ )
19
+ used_indices.add(idx)
20
+ else:
21
+ # added or incorrect word
22
+ highlighted.append(
23
+ f"<span style='background-color:#e6ffe6; color:#006600; padding:4px 10px; "
24
+ f"margin:4px; border-radius:999px; font-weight:500; display:inline-block;'>{word}</span>"
25
+ )
26
+
27
+ # find missing words
28
+ for i, word in enumerate(original_words):
29
+ if i not in used_indices:
30
+ highlighted.append(
31
+ f"<span style='background-color:#ffe6e6; color:#990000; padding:4px 10px; "
32
+ f"margin:4px; border-radius:999px; font-weight:500; display:inline-block;'>{word}</span>"
33
+ )
34
+
35
+ return " ".join(highlighted)
36
+
37
+
38
+ def check_transcription(audio_file, user_text):
39
+ transcript_path = audio_file.replace(".mp3", ".txt").replace("audio", "transcripts")
40
+ with open(transcript_path, 'r') as f:
41
+ original = f.read().strip()
42
+
43
+ diff_html = highlight_fuzzy_diff(user_text, original)
44
+ score = round(fuzz.ratio(user_text, original))
45
+
46
+ # Emoji based on score
47
+ if score > 90:
48
+ emoji = "✅"
49
+ comment = "Great job! Keep it up."
50
+ elif score > 70:
51
+ emoji = "⚠️"
52
+ comment = "Not bad, but pay attention to some words."
53
+ else:
54
+ emoji = "❌"
55
+ comment = "Try again. There are too many mistakes."
56
+
57
+ feedback = f"""
58
+ <div style='font-size: 16px; margin-bottom: 6px;'>
59
+ Similarity: <b>{score}%</b> {emoji}
60
+ </div>
61
+ <div style='margin-top: 4px;'>{comment}</div>
62
+ """
63
+
64
+ return original, (
65
+ "<div style='margin-bottom: 10px;'><b>🟩 Extra / incorrect words</b>, "
66
+ "<b>🟥 Missing words</b>, <b>⬜ Correct words</b></div>" + diff_html
67
+ ), feedback
68
+
69
+
70
+ audio_list = ["audio/lesson1.mp3", "audio/lesson2.mp3", "audio/lesson3.mp3"]
71
+
72
+ gr.Interface(
73
+ fn=check_transcription,
74
+ inputs=[
75
+ gr.Dropdown(audio_list, label="Select an audio file"),
76
+ gr.Textbox(lines=6, label="Your transcription"),
77
+ ],
78
+ outputs=[
79
+ gr.Textbox(label="Original text"),
80
+ gr.HTML(label="Comparison (highlighted)"),
81
+ gr.HTML(label="Feedback and score"),
82
+ ],
83
+ title="🎧 English Transcription Checker",
84
+ description="Listen to the audio, type your transcription, and check how accurate it is.",
85
+ theme="soft" # or "default" / "gradio/soft"
86
+ ).launch()
audio_generator.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from gtts import gTTS
4
+
5
+ demo_texts = {
6
+ "lesson1": "Hello! My name is Anna. I live in London and I work as a teacher.",
7
+ "lesson2": "Every morning, I wake up at 7 o'clock and have a cup of coffee.",
8
+ "lesson3": "On weekends, I like to go to the park and read books in the sun."
9
+ }
10
+
11
+ os.makedirs("audio", exist_ok=True)
12
+ os.makedirs("transcripts", exist_ok=True)
13
+
14
+ for name, text in demo_texts.items():
15
+ with open(f"transcripts/{name}.txt", "w") as f:
16
+ f.write(text)
17
+
18
+ tts = gTTS(text)
19
+ tts.save(f"audio/{name}.mp3")
20
+
21
+ print("Audio files and transcripts generated successfully.")
feedback/feedback.py ADDED
File without changes
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ pip~=24.3.1
transcripts/lesson1.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Hello! My name is Anna. I live in London and I work as a teacher.
transcripts/lesson2.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Every morning, I wake up at 7 o'clock and have a cup of coffee.
transcripts/lesson3.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ On weekends, I like to go to the park and read books in the sun.