Vadym Myroshnyk commited on
Commit
ac3dedf
·
1 Parent(s): edf0091
Files changed (3) hide show
  1. app.py +2 -1
  2. check.py → dialogue.py +0 -46
  3. style.css +0 -128
app.py CHANGED
@@ -3,7 +3,8 @@ import gradio as gr
3
  from rapidfuzz import fuzz
4
 
5
  from audio_files import get_audio_structure
6
- from check import load_dialogue_lines, highlight_fuzzy_diff # додано highlight_fuzzy_diff
 
7
 
8
  # === Audio structure ===
9
  audio_structure = get_audio_structure()
 
3
  from rapidfuzz import fuzz
4
 
5
  from audio_files import get_audio_structure
6
+ from dialogue import load_dialogue_lines # додано highlight_fuzzy_diff
7
+ from highlighter import highlight_fuzzy_diff
8
 
9
  # === Audio structure ===
10
  audio_structure = get_audio_structure()
check.py → dialogue.py RENAMED
@@ -1,10 +1,3 @@
1
- import os
2
-
3
- from rapidfuzz import fuzz
4
-
5
- from highlighter import highlight_fuzzy_diff
6
-
7
-
8
  def format_as_dialogue(text: str) -> str:
9
  """Formats raw transcript text into styled HTML dialogue."""
10
  lines = text.strip().split('\n')
@@ -20,45 +13,6 @@ def format_as_dialogue(text: str) -> str:
20
  return "<div class='dialogue-text'>" + "".join(html_lines) + "</div>"
21
 
22
 
23
- def check_transcription(audio_path, user_text):
24
- transcript_path = audio_path.replace(".mp3", ".txt").replace("audio", "transcripts")
25
-
26
- if not os.path.exists(transcript_path):
27
- return audio_path, "<p style='color:red;'>Transcript not found.</p>", "", "<p>❌ No transcript file found.</p>"
28
-
29
- with open(transcript_path, 'r') as f:
30
- original = f.read().strip()
31
-
32
- diff_html = highlight_fuzzy_diff(user_text, original)
33
- score = round(fuzz.ratio(user_text, original))
34
-
35
- # Emoji feedback
36
- if score > 90:
37
- emoji = "✅"
38
- comment = "Great job! Keep it up."
39
- elif score > 70:
40
- emoji = "⚠️"
41
- comment = "Not bad, but pay attention to some words."
42
- else:
43
- emoji = "❌"
44
- comment = "Try again. There are too many mistakes."
45
-
46
- simple_feedback = f"""
47
- <div style='font-size: 16px; margin-bottom: 6px;'>
48
- Similarity: <b>{score}%</b> {emoji}
49
- </div>
50
- <div style='margin-top: 4px;'>{comment}</div>
51
- """
52
-
53
- return (
54
- audio_path,
55
- format_as_dialogue(original),
56
- "<div style='margin-bottom: 10px;'><b>⬜ Extra / incorrect words</b>, "
57
- "<b>🟥 Missing words</b>, <b>🟩 Correct words</b></div>" + diff_html,
58
- simple_feedback
59
- )
60
-
61
-
62
  def load_dialogue_lines(path):
63
  with open(path, "r", encoding="utf-8") as f:
64
  lines = []
 
 
 
 
 
 
 
 
1
  def format_as_dialogue(text: str) -> str:
2
  """Formats raw transcript text into styled HTML dialogue."""
3
  lines = text.strip().split('\n')
 
13
  return "<div class='dialogue-text'>" + "".join(html_lines) + "</div>"
14
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def load_dialogue_lines(path):
17
  with open(path, "r", encoding="utf-8") as f:
18
  lines = []
style.css DELETED
@@ -1,128 +0,0 @@
1
- /* Base styles */
2
- body, .gradio-container {
3
- background: #f4f6f8;
4
- font-family: 'Inter', sans-serif;
5
- color: #111;
6
- }
7
-
8
- /* Header */
9
- h1, h2, h3, h4 {
10
- color: #222;
11
- font-weight: 700;
12
- margin-bottom: 0.5em;
13
- }
14
-
15
- /* Dropdowns and audio row */
16
- div[class*="gr-row"] > div {
17
- padding: 8px;
18
- }
19
-
20
- /* Dropdown styling */
21
- label {
22
- font-weight: 600;
23
- color: #444;
24
- font-size: 16px;
25
- }
26
-
27
- select, .gr-box input[type="text"] {
28
- padding: 10px;
29
- font-size: 15px;
30
- border-radius: 8px;
31
- border: 1px solid #ccc;
32
- width: 100%;
33
- }
34
-
35
- /* Audio player styling */
36
- .gradio-audio {
37
- border-radius: 12px;
38
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
39
- }
40
-
41
- /* Textboxes */
42
- textarea, input[type="text"] {
43
- font-size: 16px;
44
- line-height: 1.6;
45
- padding: 12px;
46
- border-radius: 8px;
47
- border: 1px solid #ccc;
48
- background-color: #fff;
49
- color: #222;
50
- resize: vertical;
51
- }
52
-
53
- /* Feedback panel */
54
- .gr-html {
55
- padding: 16px;
56
- background: #ffffff;
57
- border: 1px solid #ddd;
58
- border-radius: 10px;
59
- margin-top: 12px;
60
- }
61
-
62
- /* Button */
63
- button {
64
- background: linear-gradient(90deg, #4f46e5, #3b82f6);
65
- color: white;
66
- border: none;
67
- border-radius: 8px;
68
- padding: 12px 20px;
69
- font-size: 16px;
70
- font-weight: 600;
71
- cursor: pointer;
72
- transition: 0.3s ease;
73
- }
74
-
75
- button:hover {
76
- background: linear-gradient(90deg, #4338ca, #2563eb);
77
- }
78
-
79
- /* Markdown title */
80
- .gr-markdown {
81
- font-size: 26px !important;
82
- text-align: center;
83
- color: #111827;
84
- margin-bottom: 20px;
85
- }
86
-
87
- /* Improve spacing between blocks */
88
- .gradio-container .block {
89
- margin-bottom: 20px;
90
- }
91
-
92
- .dialogue-text p {
93
- font-size: 16px;
94
- line-height: 1.6;
95
- margin-bottom: 6px;
96
- font-family: "Segoe UI", sans-serif;
97
- color: #222;
98
- }
99
-
100
- .dialogue-text strong {
101
- color: #1a73e8;
102
- margin-right: 8px;
103
- }
104
-
105
- /* Diff word highlights */
106
- span[style*="background-color:#f0f0f0"] {
107
- background-color: #e6f2ff !important;
108
- color: #004080 !important;
109
- }
110
-
111
- span[style*="background-color:#e6ffe6"] {
112
- background-color: #d9fdd3 !important;
113
- color: #207200 !important;
114
- }
115
-
116
- span[style*="background-color:#ffe6e6"] {
117
- background-color: #ffd6d6 !important;
118
- color: #b00020 !important;
119
- }
120
-
121
- .gr-accordion {
122
- background-color: #f9f9ff;
123
- border-radius: 10px;
124
- padding: 8px 12px;
125
- border: 1px solid #dcdcdc;
126
- font-weight: 500;
127
- font-size: 16px;
128
- }