1morecupofhottea commited on
Commit
6497d65
Β·
1 Parent(s): ec35154

Update design

Browse files
Files changed (1) hide show
  1. app.py +92 -81
app.py CHANGED
@@ -13,143 +13,154 @@ def clean_transcript(text: str) -> str:
13
 
14
  def transcribe(audio, model_choice):
15
  if audio is None:
16
- return "❌ Please upload or record an audio file first!"
17
 
18
  try:
19
- if model_choice == "🎯 Whisper (Recommended)":
20
  result = whisper_asr(audio)
21
- return f"βœ… **Transcription Complete**\n\n{result['text']}"
22
  else:
23
  result = wav2vec_asr(audio)
24
  cleaned_text = clean_transcript(result["text"])
25
- return f"βœ… **Transcription Complete**\n\n{cleaned_text}"
26
  except Exception as e:
27
- return f"❌ Error during transcription: {str(e)}"
28
 
29
  def clear_all():
30
- return None, "🎯 Whisper (Recommended)", ""
31
 
32
- # Custom CSS for modern styling
33
  custom_css = """
34
  /* Global Styles */
35
  .gradio-container {
36
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
37
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
 
38
  }
39
 
40
  /* Header Styling */
41
  .header-section {
42
- background: rgba(255, 255, 255, 0.95);
43
- border-radius: 20px;
 
44
  padding: 30px;
45
  margin-bottom: 25px;
46
- box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
47
- backdrop-filter: blur(10px);
48
- border: 1px solid rgba(255, 255, 255, 0.2);
49
  }
50
 
51
  .header-section h1 {
52
- background: linear-gradient(45deg, #667eea, #764ba2);
53
- -webkit-background-clip: text;
54
- -webkit-text-fill-color: transparent;
55
- font-size: 2.5em !important;
56
- font-weight: 700 !important;
57
  text-align: center;
58
  margin-bottom: 15px;
 
 
59
  }
60
 
61
  .header-section p {
62
- color: #555;
63
  font-size: 1.1em;
64
  text-align: center;
65
- margin: 0;
66
- line-height: 1.6;
67
  }
68
 
69
  /* Main Content Cards */
70
  .input-card, .output-card {
71
- background: rgba(255, 255, 255, 0.95);
72
- border-radius: 15px;
 
73
  padding: 25px;
74
- box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
75
- backdrop-filter: blur(10px);
76
- border: 1px solid rgba(255, 255, 255, 0.2);
77
  margin-bottom: 20px;
78
  }
79
 
80
  /* Button Styling */
81
  .primary-button {
82
- background: linear-gradient(45deg, #667eea, #764ba2) !important;
83
- border: none !important;
84
- border-radius: 12px !important;
85
- padding: 15px 30px !important;
86
- font-size: 1.1em !important;
87
  font-weight: 600 !important;
88
  color: white !important;
89
- box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4) !important;
90
- transition: all 0.3s ease !important;
91
  }
92
 
93
  .primary-button:hover {
94
- transform: translateY(-2px) !important;
95
- box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6) !important;
96
  }
97
 
98
  .secondary-button {
99
- background: linear-gradient(45deg, #ff6b6b, #ee5a24) !important;
100
- border: none !important;
101
- border-radius: 12px !important;
102
- padding: 12px 25px !important;
103
- font-size: 1em !important;
104
- font-weight: 600 !important;
105
  color: white !important;
106
- box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4) !important;
 
 
 
 
107
  }
108
 
109
  /* Audio Component Styling */
110
  .audio-component {
111
- border-radius: 12px !important;
112
- border: 2px solid #e1e8f7 !important;
113
- background: #f8faff !important;
114
  }
115
 
116
  /* Dropdown Styling */
117
  .dropdown-component {
118
- border-radius: 12px !important;
119
- border: 2px solid #e1e8f7 !important;
 
120
  }
121
 
122
  /* Output Text Styling */
123
  .output-text {
124
- background: #f8faff !important;
125
- border-radius: 12px !important;
126
- border: 2px solid #e1e8f7 !important;
127
  padding: 20px !important;
128
- font-size: 1.05em !important;
129
  line-height: 1.6 !important;
 
130
  }
131
 
132
  /* Features Section */
133
  .features-section {
134
- background: rgba(255, 255, 255, 0.95);
135
- border-radius: 15px;
 
136
  padding: 25px;
137
  margin-top: 25px;
138
- box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
139
- backdrop-filter: blur(10px);
140
- border: 1px solid rgba(255, 255, 255, 0.2);
141
  }
142
 
143
  .feature-item {
144
- margin-bottom: 10px;
145
- color: #555;
146
- font-size: 1.05em;
 
 
 
 
 
 
 
 
147
  }
148
 
149
  /* Responsive Design */
150
  @media (max-width: 768px) {
151
  .header-section h1 {
152
- font-size: 2em !important;
153
  }
154
 
155
  .input-card, .output-card {
@@ -160,20 +171,20 @@ custom_css = """
160
  """
161
 
162
  # Create the main interface
163
- with gr.Blocks(css=custom_css, title="πŸŽ™οΈ CS-ASR | Code-Switching Speech Recognition") as demo:
164
  # Header Section
165
  with gr.Column(elem_classes="header-section"):
166
  gr.HTML("""
167
- <h1>πŸŽ™οΈ Code-Switching ASR Studio</h1>
168
- <p>Advanced Speech Recognition for Khmer-English Code-Switching</p>
169
- <p>✨ Powered by state-of-the-art Whisper and Wav2Vec2 models ✨</p>
170
  """)
171
 
172
  # Main Content
173
  with gr.Row():
174
  # Input Section
175
  with gr.Column(scale=1, elem_classes="input-card"):
176
- gr.HTML("<h3 style='color: #667eea; margin-bottom: 20px; font-weight: 600;'>🎡 Audio Input</h3>")
177
 
178
  audio_input = gr.Audio(
179
  sources=["microphone", "upload"],
@@ -184,11 +195,11 @@ with gr.Blocks(css=custom_css, title="πŸŽ™οΈ CS-ASR | Code-Switching Speech Rec
184
 
185
  model_selector = gr.Dropdown(
186
  choices=[
187
- "🎯 Whisper (Recommended)",
188
- "⚑ Wav2Vec2 (Fast)"
189
  ],
190
- value="🎯 Whisper (Recommended)",
191
- label="πŸ€– Select AI Model",
192
  elem_classes="dropdown-component",
193
  info="Choose the model that best fits your needs"
194
  )
@@ -196,24 +207,24 @@ with gr.Blocks(css=custom_css, title="πŸŽ™οΈ CS-ASR | Code-Switching Speech Rec
196
  # Action Buttons
197
  with gr.Row():
198
  transcribe_button = gr.Button(
199
- "πŸš€ Start Transcription",
200
  variant="primary",
201
  elem_classes="primary-button",
202
  scale=2
203
  )
204
  clear_button = gr.Button(
205
- "πŸ—‘οΈ Clear All",
206
  elem_classes="secondary-button",
207
  scale=1
208
  )
209
 
210
  # Output Section
211
  with gr.Column(scale=1, elem_classes="output-card"):
212
- gr.HTML("<h3 style='color: #667eea; margin-bottom: 20px; font-weight: 600;'>πŸ“ Transcription Result</h3>")
213
 
214
  output_text = gr.Textbox(
215
  label="Your Transcription Will Appear Here",
216
- placeholder="🎀 Upload an audio file and click 'Start Transcription' to see the magic happen!",
217
  lines=12,
218
  elem_classes="output-text",
219
  interactive=False
@@ -222,25 +233,25 @@ with gr.Blocks(css=custom_css, title="πŸŽ™οΈ CS-ASR | Code-Switching Speech Rec
222
  # Features Section
223
  with gr.Column(elem_classes="features-section"):
224
  gr.HTML("""
225
- <h3 style='color: #667eea; margin-bottom: 20px; font-weight: 600; text-align: center;'>🌟 Key Features</h3>
226
  <div style='display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-top: 20px;'>
227
  <div class='feature-item'>
228
- <strong>🎯 Dual Model Support:</strong> Choose between Whisper and Wav2Vec2 for optimal results
229
  </div>
230
  <div class='feature-item'>
231
- <strong>🌍 Code-Switching Ready:</strong> Seamlessly handles Khmer-English mixed speech
232
  </div>
233
  <div class='feature-item'>
234
- <strong>🎀 Flexible Input:</strong> Record live or upload existing audio files
235
  </div>
236
  <div class='feature-item'>
237
- <strong>⚑ Real-time Processing:</strong> Fast and accurate transcription results
238
  </div>
239
  <div class='feature-item'>
240
- <strong>🎨 Modern Interface:</strong> Beautiful, responsive design for all devices
241
  </div>
242
  <div class='feature-item'>
243
- <strong>πŸ”§ Easy to Use:</strong> No technical knowledge required - just click and transcribe!
244
  </div>
245
  </div>
246
  """)
 
13
 
14
  def transcribe(audio, model_choice):
15
  if audio is None:
16
+ return "Please upload or record an audio file first."
17
 
18
  try:
19
+ if model_choice == "Whisper (Recommended)":
20
  result = whisper_asr(audio)
21
+ return f"Transcription Complete:\n\n{result['text']}"
22
  else:
23
  result = wav2vec_asr(audio)
24
  cleaned_text = clean_transcript(result["text"])
25
+ return f"Transcription Complete:\n\n{cleaned_text}"
26
  except Exception as e:
27
+ return f"Error during transcription: {str(e)}"
28
 
29
  def clear_all():
30
+ return None, "Whisper (Recommended)", ""
31
 
32
+ # Custom CSS for classic professional styling
33
  custom_css = """
34
  /* Global Styles */
35
  .gradio-container {
36
+ background: #f8f9fa !important;
37
+ font-family: 'Times New Roman', Georgia, serif !important;
38
+ color: #2c3e50 !important;
39
  }
40
 
41
  /* Header Styling */
42
  .header-section {
43
+ background: #ffffff;
44
+ border: 2px solid #dee2e6;
45
+ border-radius: 8px;
46
  padding: 30px;
47
  margin-bottom: 25px;
48
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
 
 
49
  }
50
 
51
  .header-section h1 {
52
+ color: #2c3e50 !important;
53
+ font-size: 2.2em !important;
54
+ font-weight: 600 !important;
 
 
55
  text-align: center;
56
  margin-bottom: 15px;
57
+ border-bottom: 3px solid #34495e;
58
+ padding-bottom: 15px;
59
  }
60
 
61
  .header-section p {
62
+ color: #5a6c7d;
63
  font-size: 1.1em;
64
  text-align: center;
65
+ margin: 8px 0;
66
+ line-height: 1.5;
67
  }
68
 
69
  /* Main Content Cards */
70
  .input-card, .output-card {
71
+ background: #ffffff;
72
+ border: 2px solid #dee2e6;
73
+ border-radius: 8px;
74
  padding: 25px;
75
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
 
 
76
  margin-bottom: 20px;
77
  }
78
 
79
  /* Button Styling */
80
  .primary-button {
81
+ background: #34495e !important;
82
+ border: 2px solid #2c3e50 !important;
83
+ border-radius: 6px !important;
84
+ padding: 12px 24px !important;
85
+ font-size: 1em !important;
86
  font-weight: 600 !important;
87
  color: white !important;
88
+ transition: all 0.2s ease !important;
 
89
  }
90
 
91
  .primary-button:hover {
92
+ background: #2c3e50 !important;
93
+ border-color: #1a252f !important;
94
  }
95
 
96
  .secondary-button {
97
+ background: #6c757d !important;
98
+ border: 2px solid #5a6268 !important;
99
+ border-radius: 6px !important;
100
+ padding: 10px 20px !important;
101
+ font-size: 0.95em !important;
102
+ font-weight: 500 !important;
103
  color: white !important;
104
+ }
105
+
106
+ .secondary-button:hover {
107
+ background: #5a6268 !important;
108
+ border-color: #495057 !important;
109
  }
110
 
111
  /* Audio Component Styling */
112
  .audio-component {
113
+ border-radius: 6px !important;
114
+ border: 2px solid #ced4da !important;
115
+ background: #ffffff !important;
116
  }
117
 
118
  /* Dropdown Styling */
119
  .dropdown-component {
120
+ border-radius: 6px !important;
121
+ border: 2px solid #ced4da !important;
122
+ background: #ffffff !important;
123
  }
124
 
125
  /* Output Text Styling */
126
  .output-text {
127
+ background: #ffffff !important;
128
+ border-radius: 6px !important;
129
+ border: 2px solid #ced4da !important;
130
  padding: 20px !important;
131
+ font-size: 1em !important;
132
  line-height: 1.6 !important;
133
+ font-family: 'Courier New', monospace !important;
134
  }
135
 
136
  /* Features Section */
137
  .features-section {
138
+ background: #ffffff;
139
+ border: 2px solid #dee2e6;
140
+ border-radius: 8px;
141
  padding: 25px;
142
  margin-top: 25px;
143
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
 
 
144
  }
145
 
146
  .feature-item {
147
+ margin-bottom: 12px;
148
+ color: #495057;
149
+ font-size: 1em;
150
+ line-height: 1.5;
151
+ }
152
+
153
+ /* Professional Typography */
154
+ h3 {
155
+ font-family: 'Times New Roman', Georgia, serif !important;
156
+ color: #2c3e50 !important;
157
+ font-weight: 600 !important;
158
  }
159
 
160
  /* Responsive Design */
161
  @media (max-width: 768px) {
162
  .header-section h1 {
163
+ font-size: 1.8em !important;
164
  }
165
 
166
  .input-card, .output-card {
 
171
  """
172
 
173
  # Create the main interface
174
+ with gr.Blocks(css=custom_css, title="CS-ASR | Code-Switching Speech Recognition") as demo:
175
  # Header Section
176
  with gr.Column(elem_classes="header-section"):
177
  gr.HTML("""
178
+ <h1>Code-Switching ASR Platform</h1>
179
+ <p>Professional Speech Recognition for Khmer-English Code-Switching</p>
180
+ <p>Powered by Advanced Whisper and Wav2Vec2 Models</p>
181
  """)
182
 
183
  # Main Content
184
  with gr.Row():
185
  # Input Section
186
  with gr.Column(scale=1, elem_classes="input-card"):
187
+ gr.HTML("<h3 style='color: #2c3e50; margin-bottom: 20px; font-weight: 600;'>Audio Input</h3>")
188
 
189
  audio_input = gr.Audio(
190
  sources=["microphone", "upload"],
 
195
 
196
  model_selector = gr.Dropdown(
197
  choices=[
198
+ "Whisper (Recommended)",
199
+ "Wav2Vec2 (Fast)"
200
  ],
201
+ value="Whisper (Recommended)",
202
+ label="Select AI Model",
203
  elem_classes="dropdown-component",
204
  info="Choose the model that best fits your needs"
205
  )
 
207
  # Action Buttons
208
  with gr.Row():
209
  transcribe_button = gr.Button(
210
+ "Start Transcription",
211
  variant="primary",
212
  elem_classes="primary-button",
213
  scale=2
214
  )
215
  clear_button = gr.Button(
216
+ "Clear All",
217
  elem_classes="secondary-button",
218
  scale=1
219
  )
220
 
221
  # Output Section
222
  with gr.Column(scale=1, elem_classes="output-card"):
223
+ gr.HTML("<h3 style='color: #2c3e50; margin-bottom: 20px; font-weight: 600;'>Transcription Result</h3>")
224
 
225
  output_text = gr.Textbox(
226
  label="Your Transcription Will Appear Here",
227
+ placeholder="Upload an audio file and click 'Start Transcription' to begin processing.",
228
  lines=12,
229
  elem_classes="output-text",
230
  interactive=False
 
233
  # Features Section
234
  with gr.Column(elem_classes="features-section"):
235
  gr.HTML("""
236
+ <h3 style='color: #2c3e50; margin-bottom: 20px; font-weight: 600; text-align: center;'>Key Features</h3>
237
  <div style='display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-top: 20px;'>
238
  <div class='feature-item'>
239
+ <strong>Dual Model Support:</strong> Choose between Whisper and Wav2Vec2 for optimal results
240
  </div>
241
  <div class='feature-item'>
242
+ <strong>Code-Switching Ready:</strong> Seamlessly handles Khmer-English mixed speech
243
  </div>
244
  <div class='feature-item'>
245
+ <strong>Flexible Input:</strong> Record live or upload existing audio files
246
  </div>
247
  <div class='feature-item'>
248
+ <strong>Real-time Processing:</strong> Fast and accurate transcription results
249
  </div>
250
  <div class='feature-item'>
251
+ <strong>Professional Interface:</strong> Clean, responsive design for all devices
252
  </div>
253
  <div class='feature-item'>
254
+ <strong>Easy to Use:</strong> No technical knowledge required - just click and transcribe
255
  </div>
256
  </div>
257
  """)