sbompolas commited on
Commit
2b8223d
·
verified ·
1 Parent(s): 2bfc660

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -44
app.py CHANGED
@@ -139,48 +139,23 @@ class MultiASRApp:
139
  # ------------------------
140
  # Transcription
141
  # ------------------------
142
- def transcribe(self, audio, model_name, return_timestamps):
143
  if audio is None:
144
- return "Ανέβασε ένα ηχητικό αρχείο.", "", ""
145
 
146
  start = time.time()
147
  if not self.load_model(model_name):
148
- return "Σφάλμα φόρτωσης μοντέλου.", "", ""
149
 
150
- if self.current_kind == "ctc":
151
- result = self.pipe(audio)
152
- text = result.get("text", "")
153
 
154
- timestamps = (
155
- "Οι χρονικές σημάνσεις δεν υποστηρίζονται για αυτό το μοντέλο."
156
- if return_timestamps
157
- else ""
158
- )
159
-
160
- else:
161
- result = self.pipe(
162
- audio,
163
- return_timestamps=return_timestamps,
164
- )
165
- text = result.get("text", "")
166
- timestamps = self.format_timestamps(result.get("chunks", []))
167
-
168
- details = (
169
  f"Μοντέλο: {model_name}\n"
170
  f"Χρόνος επεξεργασίας: {time.time() - start:.2f} δευτ."
171
  )
172
 
173
- return text.strip(), timestamps, details
174
-
175
- def format_timestamps(self, chunks):
176
- if not chunks:
177
- return ""
178
- out = ""
179
- for c in chunks:
180
- ts = c.get("timestamp")
181
- if ts and ts[0] is not None and ts[1] is not None:
182
- out += f"[{ts[0]:.1f}–{ts[1]:.1f}] {c.get('text','')}\n"
183
- return out
184
 
185
  def status(self):
186
  if not self.current_model:
@@ -193,8 +168,8 @@ class MultiASRApp:
193
  # ------------------------
194
  app = MultiASRApp()
195
 
196
- def run(audio, model, timestamps):
197
- return app.transcribe(audio, model, timestamps)
198
 
199
  def status():
200
  return app.status()
@@ -214,11 +189,18 @@ with gr.Blocks(title="Ίντα λαλείς;", theme=gr.themes.Soft()) as demo:
214
  """
215
  )
216
 
217
- model_status = gr.Textbox(label="Κατάσταση μοντέλου", value=status(), interactive=False)
 
 
 
 
218
 
219
  with gr.Row():
220
  with gr.Column():
221
- audio = gr.Audio(label="🎵 Ανέβασε ηχητικό αρχείο", type="filepath")
 
 
 
222
 
223
  model = gr.Dropdown(
224
  choices=app.available_models,
@@ -226,19 +208,27 @@ with gr.Blocks(title="Ίντα λαλείς;", theme=gr.themes.Soft()) as demo:
226
  label="Μοντέλο αναγνώρισης ομιλίας",
227
  )
228
 
229
- timestamps = gr.Checkbox(label="Χρονικές σημάνσεις", value=True)
230
-
231
- btn = gr.Button("🗣️ Μετατροπή ομιλίας σε κείμενο", variant="primary")
 
232
 
233
  with gr.Column():
234
- text_out = gr.Textbox(label="📄 Κείμενο", lines=8, show_copy_button=True)
235
- ts_out = gr.Textbox(label="Χρονικές σημάνσεις", lines=8)
236
- info_out = gr.Textbox(label="Πληροφορίες", lines=4)
 
 
 
 
 
 
 
237
 
238
  btn.click(
239
  run,
240
- inputs=[audio, model, timestamps],
241
- outputs=[text_out, ts_out, info_out],
242
  )
243
 
244
  model.change(lambda _: status(), outputs=model_status)
 
139
  # ------------------------
140
  # Transcription
141
  # ------------------------
142
+ def transcribe(self, audio, model_name):
143
  if audio is None:
144
+ return "Ανέβασε ένα ηχητικό αρχείο.", ""
145
 
146
  start = time.time()
147
  if not self.load_model(model_name):
148
+ return "Σφάλμα φόρτωσης μοντέλου.", ""
149
 
150
+ result = self.pipe(audio)
151
+ text = result.get("text", "")
 
152
 
153
+ info = (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  f"Μοντέλο: {model_name}\n"
155
  f"Χρόνος επεξεργασίας: {time.time() - start:.2f} δευτ."
156
  )
157
 
158
+ return text.strip(), info
 
 
 
 
 
 
 
 
 
 
159
 
160
  def status(self):
161
  if not self.current_model:
 
168
  # ------------------------
169
  app = MultiASRApp()
170
 
171
+ def run(audio, model):
172
+ return app.transcribe(audio, model)
173
 
174
  def status():
175
  return app.status()
 
189
  """
190
  )
191
 
192
+ model_status = gr.Textbox(
193
+ label="Κατάσταση μοντέλου",
194
+ value=status(),
195
+ interactive=False,
196
+ )
197
 
198
  with gr.Row():
199
  with gr.Column():
200
+ audio = gr.Audio(
201
+ label="🎵 Ανέβασε ηχητικό αρχείο",
202
+ type="filepath",
203
+ )
204
 
205
  model = gr.Dropdown(
206
  choices=app.available_models,
 
208
  label="Μοντέλο αναγνώρισης ομιλίας",
209
  )
210
 
211
+ btn = gr.Button(
212
+ "🗣️ Μετατροπή ομιλίας σε κείμενο",
213
+ variant="primary",
214
+ )
215
 
216
  with gr.Column():
217
+ text_out = gr.Textbox(
218
+ label="📄 Κείμενο",
219
+ lines=8,
220
+ show_copy_button=True,
221
+ )
222
+
223
+ info_out = gr.Textbox(
224
+ label="Πληροφορίες",
225
+ lines=4,
226
+ )
227
 
228
  btn.click(
229
  run,
230
+ inputs=[audio, model],
231
+ outputs=[text_out, info_out],
232
  )
233
 
234
  model.change(lambda _: status(), outputs=model_status)