mguven61 commited on
Commit
a4b5ff1
·
verified ·
1 Parent(s): 1230d11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -15
app.py CHANGED
@@ -2,22 +2,17 @@ import gradio as gr
2
  from detect import SimpleOfflineAccentClassifier
3
  import yt_dlp
4
  import os
5
- import subprocess
6
  import tempfile
 
7
 
8
- # FFmpeg kurulumu
9
- def install_ffmpeg():
10
- try:
11
- subprocess.run(['apt-get', 'update'], check=True)
12
- subprocess.run(['apt-get', 'install', '-y', 'ffmpeg'], check=True)
13
- except Exception as e:
14
- print(f"FFmpeg installation error: {e}")
15
-
16
- # FFmpeg'i kur
17
- install_ffmpeg()
18
 
19
  def download_youtube_audio(url):
20
  try:
 
 
21
  # Geçici dosya yolu oluştur
22
  temp_dir = tempfile.gettempdir()
23
  temp_file = os.path.join(temp_dir, 'temp_audio.wav')
@@ -30,20 +25,32 @@ def download_youtube_audio(url):
30
  }],
31
  'outtmpl': temp_file.replace('.wav', ''),
32
  'quiet': True,
33
- 'no_warnings': True
 
 
 
 
34
  }
35
 
36
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
 
37
  ydl.download([url])
 
38
 
39
- return temp_file
 
 
 
 
 
40
  except Exception as e:
41
- print(f"YouTube download error: {e}")
42
  return None
43
 
44
  def analyze_audio(audio_file, youtube_url):
45
  try:
46
  if youtube_url:
 
47
  audio_file = download_youtube_audio(youtube_url)
48
  if not audio_file:
49
  return "Failed to download YouTube audio. Please check the URL and try again."
@@ -51,6 +58,7 @@ def analyze_audio(audio_file, youtube_url):
51
  if not audio_file:
52
  return "Please upload an audio file or provide a YouTube URL."
53
 
 
54
  classifier = SimpleOfflineAccentClassifier()
55
  result = classifier.predict_accent(audio_file)
56
 
@@ -74,6 +82,7 @@ def analyze_audio(audio_file, youtube_url):
74
  return output
75
 
76
  except Exception as e:
 
77
  return f"Error occurred: {str(e)}"
78
 
79
  # Create Gradio interface
@@ -107,4 +116,4 @@ with gr.Blocks() as interface:
107
  )
108
 
109
  # Launch the interface
110
- interface.launch()
 
2
  from detect import SimpleOfflineAccentClassifier
3
  import yt_dlp
4
  import os
 
5
  import tempfile
6
+ import logging
7
 
8
+ # Logging ayarları
9
+ logging.basicConfig(level=logging.DEBUG)
10
+ logger = logging.getLogger(__name__)
 
 
 
 
 
 
 
11
 
12
  def download_youtube_audio(url):
13
  try:
14
+ logger.debug(f"Downloading from URL: {url}")
15
+
16
  # Geçici dosya yolu oluştur
17
  temp_dir = tempfile.gettempdir()
18
  temp_file = os.path.join(temp_dir, 'temp_audio.wav')
 
25
  }],
26
  'outtmpl': temp_file.replace('.wav', ''),
27
  'quiet': True,
28
+ 'no_warnings': True,
29
+ 'extract_flat': True, # Sadece ses indir
30
+ 'noplaylist': True, # Playlist değil
31
+ 'no_warnings': True,
32
+ 'ignoreerrors': True
33
  }
34
 
35
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
36
+ logger.debug("Starting download...")
37
  ydl.download([url])
38
+ logger.debug(f"Download complete. File saved to: {temp_file}")
39
 
40
+ if os.path.exists(temp_file):
41
+ return temp_file
42
+ else:
43
+ logger.error("Downloaded file not found")
44
+ return None
45
+
46
  except Exception as e:
47
+ logger.exception(f"Download error: {str(e)}")
48
  return None
49
 
50
  def analyze_audio(audio_file, youtube_url):
51
  try:
52
  if youtube_url:
53
+ logger.debug(f"Processing YouTube URL: {youtube_url}")
54
  audio_file = download_youtube_audio(youtube_url)
55
  if not audio_file:
56
  return "Failed to download YouTube audio. Please check the URL and try again."
 
58
  if not audio_file:
59
  return "Please upload an audio file or provide a YouTube URL."
60
 
61
+ logger.debug(f"Processing audio file: {audio_file}")
62
  classifier = SimpleOfflineAccentClassifier()
63
  result = classifier.predict_accent(audio_file)
64
 
 
82
  return output
83
 
84
  except Exception as e:
85
+ logger.exception(f"Analysis error: {str(e)}")
86
  return f"Error occurred: {str(e)}"
87
 
88
  # Create Gradio interface
 
116
  )
117
 
118
  # Launch the interface
119
+ interface.launch(debug=True)