mguven61 commited on
Commit
629a6d4
·
verified ·
1 Parent(s): 9c3df3c

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ import yt_dlp
3
+ import os
4
+ from detect import SimpleOfflineAccentClassifier
5
+
6
+ app = Flask(__name__)
7
+ classifier = SimpleOfflineAccentClassifier()
8
+
9
+ @app.route('/')
10
+ def home():
11
+ return render_template('index.html')
12
+
13
+ @app.route('/analyze', methods=['POST'])
14
+ def analyze():
15
+ try:
16
+ video_url = request.form['url']
17
+
18
+ # YouTube'dan ses indir
19
+ ydl_opts = {
20
+ 'format': 'bestaudio/best',
21
+ 'postprocessors': [{
22
+ 'key': 'FFmpegExtractAudio',
23
+ 'preferredcodec': 'wav',
24
+ }],
25
+ 'outtmpl': 'temp_audio',
26
+ 'quiet': True,
27
+ 'no_warnings': True
28
+ }
29
+
30
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
31
+ ydl.download([video_url])
32
+
33
+ # Ses dosyasını analiz et
34
+ result = classifier.predict_accent('temp_audio.wav')
35
+
36
+ # Geçici dosyayı temizle
37
+ if os.path.exists('temp_audio.wav'):
38
+ os.remove('temp_audio.wav')
39
+
40
+ if result is None:
41
+ return jsonify({'error': 'voice analyze failed.'})
42
+
43
+ return jsonify(result)
44
+
45
+ except Exception as e:
46
+ return jsonify({'error': str(e)})
47
+
48
+ if __name__ == '__main__':
49
+ app.run(debug=True, port=5000)