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