dini15 commited on
Commit
8107aa0
·
verified ·
1 Parent(s): 3bfabc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import yt_dlp
3
  import torch
4
  import numpy as np
5
  from faster_whisper import WhisperModel
 
6
 
7
  # Load model sekali aja
8
  model = WhisperModel("small", device="cpu", compute_type="float32")
@@ -13,7 +14,8 @@ def transcribe_audio(file):
13
  transcript = "\n".join(segment.text for segment in segments)
14
 
15
  # Simpan ke file TXT
16
- with open("transcription.txt", "w", encoding="utf-8") as f:
 
17
  f.write(transcript)
18
 
19
  return f"**Transcription:**\n{transcript}"
@@ -34,6 +36,11 @@ def transcribe_youtube(url):
34
  audio_file = get_audio_from_youtube(url)
35
  return transcribe_audio(audio_file)
36
 
 
 
 
 
 
37
  # Gradio UI
38
  with gr.Blocks() as app:
39
  gr.Markdown("# 🎤 YouTube & Audio Transcriber with Whisper AI")
 
3
  import torch
4
  import numpy as np
5
  from faster_whisper import WhisperModel
6
+ import os
7
 
8
  # Load model sekali aja
9
  model = WhisperModel("small", device="cpu", compute_type="float32")
 
14
  transcript = "\n".join(segment.text for segment in segments)
15
 
16
  # Simpan ke file TXT
17
+ file_path = "transcription.txt"
18
+ with open(file_path, "w", encoding="utf-8") as f:
19
  f.write(transcript)
20
 
21
  return f"**Transcription:**\n{transcript}"
 
36
  audio_file = get_audio_from_youtube(url)
37
  return transcribe_audio(audio_file)
38
 
39
+ #memastikan file ada sebelum digunakan
40
+ if not os.path.exists('transcription.txt'):
41
+ with open("transcription.txt", "w", encoding="utf-8") as f:
42
+ f.write("")
43
+
44
  # Gradio UI
45
  with gr.Blocks() as app:
46
  gr.Markdown("# 🎤 YouTube & Audio Transcriber with Whisper AI")