LiamKhoaLe commited on
Commit
582b2bf
·
1 Parent(s): 4c24458

Upd safe batcher and btn for download file

Browse files
Files changed (1) hide show
  1. app.py +44 -7
app.py CHANGED
@@ -144,7 +144,8 @@ def transcribe(inputs, task, summarize=False):
144
  running_summary += ("\n\n" if running_summary else "") + summarize_with_gemini(partial)
145
  except Exception:
146
  pass
147
- yield running_text, (running_summary if summarize else "")
 
148
 
149
  try:
150
  if isinstance(inputs, str):
@@ -165,8 +166,18 @@ def transcribe(inputs, task, summarize=False):
165
  summ = summarize_with_gemini(out)
166
  except Exception as e:
167
  summ = f"Summary error: {e}"
168
- return out, summ
169
- return out, ""
 
 
 
 
 
 
 
 
 
 
170
  except Exception as e:
171
  raise gr.Error(f"Transcription failed: {e}")
172
 
@@ -233,7 +244,17 @@ def yt_transcribe(yt_url, task, summarize=False, max_filesize=75.0):
233
  summary = summarize_with_gemini(text)
234
  except Exception as e:
235
  summary = f"Summary error: {e}"
236
- return html_embed_str, text, summary
 
 
 
 
 
 
 
 
 
 
237
 
238
 
239
  demo = gr.Blocks()
@@ -245,7 +266,12 @@ mf_transcribe = gr.Interface(
245
  gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
246
  gr.Checkbox(label="Summarize with Gemini", value=False),
247
  ],
248
- outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")],
 
 
 
 
 
249
  title="Whisper Large V3: Microphone",
250
  description=(
251
  "Transcribe long-form microphone or audio inputs."
@@ -260,7 +286,12 @@ file_transcribe = gr.Interface(
260
  gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
261
  gr.Checkbox(label="Summarize with Gemini", value=False),
262
  ],
263
- outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")],
 
 
 
 
 
264
  title="Whisper Large V3: Audio file",
265
  description=(
266
  "Transcribe long-form microphone or audio inputs."
@@ -275,7 +306,13 @@ yt_transcribe = gr.Interface(
275
  gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
276
  gr.Checkbox(label="Summarize with Gemini", value=False),
277
  ],
278
- outputs=["html", gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")],
 
 
 
 
 
 
279
  title="Whisper Large V3: Transcribe YouTube",
280
  description=(
281
  "Transcribe long-form YouTube videos."
 
144
  running_summary += ("\n\n" if running_summary else "") + summarize_with_gemini(partial)
145
  except Exception:
146
  pass
147
+ # Files are not ready during streaming
148
+ yield running_text, (running_summary if summarize else ""), None, None
149
 
150
  try:
151
  if isinstance(inputs, str):
 
166
  summ = summarize_with_gemini(out)
167
  except Exception as e:
168
  summ = f"Summary error: {e}"
169
+ # Create files for download
170
+ tf = tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False)
171
+ tf.write(out)
172
+ tf.close()
173
+ sf = tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False)
174
+ sf.write(summ)
175
+ sf.close()
176
+ return out, summ, tf.name, sf.name
177
+ tf = tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False)
178
+ tf.write(out)
179
+ tf.close()
180
+ return out, "", tf.name, None
181
  except Exception as e:
182
  raise gr.Error(f"Transcription failed: {e}")
183
 
 
244
  summary = summarize_with_gemini(text)
245
  except Exception as e:
246
  summary = f"Summary error: {e}"
247
+ # Create download files
248
+ tf = tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False)
249
+ tf.write(text)
250
+ tf.close()
251
+ sf_path = None
252
+ if summary:
253
+ sf = tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False)
254
+ sf.write(summary)
255
+ sf.close()
256
+ sf_path = sf.name
257
+ return html_embed_str, text, summary, tf.name, sf_path
258
 
259
 
260
  demo = gr.Blocks()
 
266
  gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
267
  gr.Checkbox(label="Summarize with Gemini", value=False),
268
  ],
269
+ outputs=[
270
+ gr.Textbox(label="Transcription"),
271
+ gr.Textbox(label="Summary"),
272
+ gr.File(label="Download transcription (transcribe.txt)"),
273
+ gr.File(label="Download summary (summarise.txt)")
274
+ ],
275
  title="Whisper Large V3: Microphone",
276
  description=(
277
  "Transcribe long-form microphone or audio inputs."
 
286
  gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
287
  gr.Checkbox(label="Summarize with Gemini", value=False),
288
  ],
289
+ outputs=[
290
+ gr.Textbox(label="Transcription"),
291
+ gr.Textbox(label="Summary"),
292
+ gr.File(label="Download transcription (transcribe.txt)"),
293
+ gr.File(label="Download summary (summarise.txt)")
294
+ ],
295
  title="Whisper Large V3: Audio file",
296
  description=(
297
  "Transcribe long-form microphone or audio inputs."
 
306
  gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
307
  gr.Checkbox(label="Summarize with Gemini", value=False),
308
  ],
309
+ outputs=[
310
+ "html",
311
+ gr.Textbox(label="Transcription"),
312
+ gr.Textbox(label="Summary"),
313
+ gr.File(label="Download transcription (transcribe.txt)"),
314
+ gr.File(label="Download summary (summarise.txt)")
315
+ ],
316
  title="Whisper Large V3: Transcribe YouTube",
317
  description=(
318
  "Transcribe long-form YouTube videos."