mguven61 commited on
Commit
85efa8f
·
verified ·
1 Parent(s): 8338d45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -4
app.py CHANGED
@@ -1,9 +1,36 @@
1
  import gradio as gr
2
  from detect import SimpleOfflineAccentClassifier
 
 
3
 
4
- def analyze_audio(audio_file):
5
- if audio_file is None:
6
- return "Please upload an audio file."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  try:
9
  classifier = SimpleOfflineAccentClassifier()
@@ -42,6 +69,11 @@ with gr.Blocks() as interface:
42
  type="filepath"
43
  )
44
 
 
 
 
 
 
45
  classify_btn = gr.Button("Analyze Accent")
46
 
47
  with gr.Column():
@@ -52,7 +84,7 @@ with gr.Blocks() as interface:
52
 
53
  classify_btn.click(
54
  fn=analyze_audio,
55
- inputs=audio_input,
56
  outputs=output_text
57
  )
58
 
 
1
  import gradio as gr
2
  from detect import SimpleOfflineAccentClassifier
3
+ import yt_dlp
4
+ import os
5
 
6
+ def download_youtube_audio(url):
7
+ try:
8
+ ydl_opts = {
9
+ 'format': 'bestaudio/best',
10
+ 'postprocessors': [{
11
+ 'key': 'FFmpegExtractAudio',
12
+ 'preferredcodec': 'wav',
13
+ }],
14
+ 'outtmpl': 'temp_audio',
15
+ 'quiet': True,
16
+ 'no_warnings': True
17
+ }
18
+
19
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
20
+ ydl.download([url])
21
+
22
+ return 'temp_audio.wav'
23
+ except Exception as e:
24
+ return None
25
+
26
+ def analyze_audio(audio_file, youtube_url):
27
+ if youtube_url:
28
+ audio_file = download_youtube_audio(youtube_url)
29
+ if not audio_file:
30
+ return "Failed to download YouTube audio."
31
+
32
+ if not audio_file:
33
+ return "Please upload an audio file or provide a YouTube URL."
34
 
35
  try:
36
  classifier = SimpleOfflineAccentClassifier()
 
69
  type="filepath"
70
  )
71
 
72
+ youtube_url = gr.Textbox(
73
+ label="Or enter YouTube URL",
74
+ placeholder="https://www.youtube.com/watch?v=..."
75
+ )
76
+
77
  classify_btn = gr.Button("Analyze Accent")
78
 
79
  with gr.Column():
 
84
 
85
  classify_btn.click(
86
  fn=analyze_audio,
87
+ inputs=[audio_input, youtube_url],
88
  outputs=output_text
89
  )
90