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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -49
app.py CHANGED
@@ -1,49 +1,59 @@
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)
 
 
 
 
 
 
 
 
 
 
 
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()
10
+ result = classifier.predict_accent(audio_file)
11
+
12
+ if result is None:
13
+ return "Audio file processing failed."
14
+
15
+ output = f"Predicted Accent: {result['accent']}\n"
16
+ output += f"Confidence Score: {result['confidence']:.2%}\n\n"
17
+ output += "All Probabilities:\n"
18
+
19
+ sorted_probs = sorted(
20
+ result['all_probabilities'].items(),
21
+ key=lambda x: x[1],
22
+ reverse=True
23
+ )
24
+
25
+ for accent, prob in sorted_probs:
26
+ bar = "█" * int(prob * 20)
27
+ output += f"- {accent}: {prob:.2%} {bar}\n"
28
+
29
+ return output
30
+
31
+ except Exception as e:
32
+ return f"Error occurred: {str(e)}"
33
+
34
+ # Create Gradio interface
35
+ with gr.Blocks() as interface:
36
+ gr.Markdown("# AI Accent Classifier")
37
+
38
+ with gr.Row():
39
+ with gr.Column():
40
+ audio_input = gr.Audio(
41
+ label="Upload Audio File",
42
+ type="filepath"
43
+ )
44
+
45
+ classify_btn = gr.Button("Analyze Accent")
46
+
47
+ with gr.Column():
48
+ output_text = gr.Markdown(
49
+ label="Analysis Results",
50
+ value="Analysis results will appear here..."
51
+ )
52
+
53
+ classify_btn.click(
54
+ fn=analyze_audio,
55
+ inputs=audio_input,
56
+ outputs=output_text
57
+ )
58
+
59
+ interface.launch()