File size: 1,631 Bytes
1d0abcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
import gradio as gr
from VideoAccentAnalyzer import VideoAccentAnalyzer
import ffmpeg
import os

analyzer = VideoAccentAnalyzer()


def analyze_video(url=None, video_file=None):
    if url:
        result = analyzer.analyze_video_url(url)
    elif video_file:
        result = analyzer.analyze_local_video(video_file)
    else:
        return "Please provide a video URL or upload a file"

    if 'error' in result:
        return f"❌ Error: {result['error']}"

    # Format results as markdown
    markdown = f"## 🎯 Results\n"
    markdown += f"**Predicted Accent:** {result['predicted_accent']}\n"
    markdown += f"**Confidence:** {result['accent_confidence']:.1f}%\n"
    markdown += f"**English Confidence:** {result['english_confidence']:.1f}%\n\n"
    markdown += "### πŸ“Š Probability Breakdown:\n"

    for accent, prob in sorted(result['all_probabilities'].items(),
                               key=lambda x: x[1], reverse=True):
        markdown += f"- {accent}: {prob:.1f}%\n"

    return markdown


# Create Gradio interface
interface = gr.Interface(
    fn=analyze_video,
    inputs=[
        gr.Textbox(label="Video URL (YouTube/Loom/Direct MP4)"),
        gr.File(label="Or Upload Video File", type="filepath")
    ],
    outputs=gr.Markdown(label="Analysis Results"),
    examples=[
        ["https://www.youtube.com/watch?v=NO5SbsvIjHE ", None],
        [None, "/kaggle/input/test-video.mp4"]
    ],
    title="🎧 Video Accent Analyzer",
    description="Analyze accents in videos from YouTube, Loom, or uploaded files. Supports English accents only."
)

if __name__ == "__main__":
    interface.launch()